There are two tables in mysql database academy and instructors. I want to insert values to each table in the following order(pseudo code):
- 1st INSERT INTO
academyvaluesacad_name, address, street, city, state - 2nd INSERT INTO
instructorsvaluesinstructor_name - 3rd
INSERT INTO
academyvaluesinstructor_idFROMinstructors\this records should go with the correspondingacademy_id
The third insert is based on the results of the second insert instructor_id which is auto_increment. But I want the third insert to correspond to the current academy the values where inserted to previously how can I do so?
CREATE TABLE IF NOT EXISTS `academy` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(25) NOT NULL,
`academy_id` int(11) NOT NULL,
`instructor_id` int(11) DEFAULT NULL,
`street_address` varchar(50) NOT NULL,
`city` varchar(25) NOT NULL,
`state` varchar(25) NOT NULL,
PRIMARY KEY (`id`),
KEY `instructor_id` (`instructor_id`) // Foreign KEY
);
CREATE TABLE IF NOT EXISTS `instructors` (
`instructor_id` int(11) NOT NULL AUTO_INCREMENT,
`academy_id` int(11) NOT NULL
PRIMARY KEY (`instructor_id`),
KEY `academy_id` (`academy_id`) // Foreign KEY
);