Monthly Archives: April 2015 - Page 36

When should we use @@identity or scope_identity() or ident_current()

SELECT IDENTITY() returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.

SELECT SCOPE_IDENTITY() returns the last IDENTITY value produced on a connection and within the same scope, regardless of the table that produced the value. SCOPE_IDENTITY(), like IDENTITY returns the last identity value created in the current session, but it will also limit it to your current scope as well.

SELECT IDENT_CURRENT(‘tablename’) returns the last IDENTITY value produced in a table.