last_insert_id() vs SELECT Max(ID)

前端 未结 2 1798
你的背包
你的背包 2021-01-23 06:25

Is using SELECT Max(ID) FROM table safer than using SELECT last_insert_id(), where they run as 2 separate queries?

I\'m concerned that before the last_insert_id() can r

2条回答
  •  迷失自我
    2021-01-23 07:18

    Is using SELECT Max(ID) FROM table safer than using SELECT last_insert_id()

    Definitely not, never! LAST_INSERT_ID() exists exactly for the reason you state: Other clients could have made other inserts. LAST_INSERT_ID() always gives you the last inserted ID on the current connection.

    mySQL Reference

提交回复
热议问题