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.

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>