PDA

View Full Version : inserting into two tables


_underdog
05-30-2003, 11:39 AM
I am using a mySQL database. I need to insert data into two tables where the tables are joined on the auto_increment id from the first table. Is there an easy way to do this in mySQL. How do you get the auto id to insert into the second table for the link?

stuka
06-02-2003, 11:39 AM
After inserting the first one, you can get the AutoID by it's column name in the table, then insert into the second one using that same ID. (I assume you're using a version of MySQL that doesn't support foreign keys - or are you?) Either way, the method is about the same either way, just that foreign keys would help prevent invalid data.