Difference Between SCOPE_IDENTITY, IDENT_CURRENT and @@IDENTITY

SCOPE_IDENTITY, IDENT_CURRENT, and @@IDENTITY are almost similar functions because they all return values that are inserted into identity columns but there is some slightly difference between these.

SCOPE_IDENTITY: It returns last identity value inserted into an identity column in the same scope. A scope is a module: a stored procedure, trigger, function, or batch. Therefore, two statements are in the same scope if they are in the same stored procedure, function, or batch.

IDENT_CURRENT: It returns the last identity value generated for a specified table in any session and any scope.

@@IDENTITY: It returns the last identity value for the current session. it does not check the scope.

Ebook Download
View all
Learn
View all