I am trying to insert multiple rows into two tables connected by a foreign key that is autoincrement. I can't seem to find a good solution. Tables:
eav_attribute_option
- option_id (PK, Autoincrement)
- attribute_id
- sort_order
eav_attribute_option_value
- value_id (PK, Autoincrement)
- option_id (FK)
- store_id
- value
I want to do this:
insert into eav_attribute_option(attribute_id) values(100,101,102,103,...);
insert into eav_attribute_option_value(option_id,store_id,value) values
(1,0,"English"),(1,1,"German"),(2,0,"English1"),(2,1,"German2")
What would be the best approach to this, I can't seem to find a good one. :
- Get next autoincrement then insert with it (need to lock table between)
- Insert first part, then retreive PK values, build second part and insert (data incomplete for some time, what happens on error in second part?)
- Some way to insert with join if it's possible?
Edit: Just to clarify, I am looking to use the least amount of queries possible. I know I can do last inserted id, but I don't want to kill the server with thousands of inserts.
AUTO_INCREMENT
generated values for multi inserts. – Vatev