maugch
maugch

Reputation: 1318

Mysql Batch insert doesn't update LAST_INSERT_ID

I've found an interesting solution to a problem I have with the 1st answer on this StackOverflow question: 1st answer The problem is that it doesn't work as I expected. If my table is empty, the first bulk insert work correctly but LAST_INSERT_ID returns 1 when the bulk has inserted 100 lines. If I change it and put 100 simple Insert it works. autoinc_loc_mode is set to 1.

Is there a setting to be changed?

Upvotes: 0

Views: 228

Answers (1)

designcise
designcise

Reputation: 4362

What you're experiencing is the expected behavior; from MySQL docs:

If you insert multiple rows using a single INSERT statement, LAST_INSERT_ID() returns the value generated for the first inserted row only. The reason for this is to make it possible to reproduce easily the same INSERT statement against some other server.

Upvotes: 1

Related Questions