It's not exactly like @@IDENTITY, but it's darn close:
LAST_INSERT_ID([expr])
Returns the last automatically generated value that was inserted into an AUTO_INCREMENT column.
mysql> SELECT LAST_INSERT_ID();
-> 195
The last ID that was generated is maintained in the server on a per-connection basis.
If you insert many rows at the same time with an insert statement, LAST_INSERT_ID() returns the value for the first inserted row. @@IDENTITY would return the last.
If you have multiple inserts in one statement, last_insert_id will show you the value of the first inserted row for that session. Else it will show you the last value inserted by that session.
@@IDENTITY is a synonym for last_insert_id in version 3.23.25.
Function is for Visual Basic compatibility
"If you always do what you've always done, you will always be where you've always been."
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.