Does a MySQL multi-row insert grab sequential autoincrement IDs?

前端 未结 3 1402
猫巷女王i
猫巷女王i 2020-12-06 02:35

I think this is true, but I haven\'t found anything on the web to confirm it. I can get the first id generated for the autoincrement field using last_insert_id(), but can I

3条回答
  •  渐次进展
    2020-12-06 03:11

    If you use LOCK TABLES, the batches should grab sequential id's.

    Example:

    LOCK TABLES users WRITE;
    
    UNLOCK TABLES;
    

    This will prevent multiple threads from writing to the table at the same time.

提交回复
热议问题