0

I'm inserting multiple rows like so:

INSERT INTO table (col_a,col_b) VALUES (111,'example'),
    (222,'another example'),(333,'blah'),(444,'another blah'),(555,'aldksjf')

Neither col_a or col_b are primary keys. My primary key has an auto_increment on it, let's call it table_id.

I've come across this link which indicates that I can use LAST_INSERT_ID and ROW_COUNT to determine the table_id of my previous inserts.

My question is order guaranteed? Specifically, if LAST_INSERT_ID is 15 is 15 guaranteed to have values (111,'example') and will table_id 18 guaranteed to have (444,'another blah')? Or does it simply mean that the 5 inserted rows will have ids 15 - 19 but not necessarily in the order of the values section of my statement.

Terence Chow
  • 10,755
  • 24
  • 78
  • 141
  • 1
    This topic may help you a bit.. https://stackoverflow.com/questions/7333524/how-can-i-insert-many-rows-into-a-mysql-table-and-return-the-new-ids?noredirect=1&lq=1 – Venkat Jun 06 '17 at 13:25
  • 1
    @venkat Isn't that the link in their question? – xQbert Jun 06 '17 at 13:30
  • @Venkat I saw that already and its already listed in my question. I am asking about whether the inserted rows are guaranteed to match the order of the values section of my statement, or whether it guarantees ids will be 15-19, but not necessarily in the order of the values section of my statement – Terence Chow Jun 06 '17 at 13:39

0 Answers0