How can I insert into table1 like: INSERT INTO table1 (description) VALUES ('Some test description here'); and have it return the automatically incremented ID so that I can then insert a row into table2? The description is not guaranteed to be unique. I am using a Java PreparedStatement to insert the value currently with execute()
I have the following table structure:
CREATE TABLE table1 ( table1ID INTEGER NOT NULL AUTO_INCREMENT, description VARCHAR(255) NOT NULL, CONSTRAINT PK_table1 PRIMARY KEY (table1ID) ); CREATE TABLE table2 ( table1ID INTEGER NOT NULL, personID INTEGER NOT NULL, CONSTRAINT PK_table2 PRIMARY KEY (table1ID, personID) ); ALTER TABLE table2 ADD CONSTRAINT FK_table1_table2 FOREIGN KEY (table1ID) REFERENCES table1 (table1ID); ALTER TABLE table2 ADD CONSTRAINT FK_table2_person FOREIGN KEY (personID) REFERENCES person (personID);