- Ident_current returns the last identity value generated for a specific table in any session and any scope.
- @ Identity returns the last identity value generated for any table in the current session, using SS all scopes.
- Scope_identity returns the last identity value generated for any table in the current session and the current scope.
Ident_current is not limited by scope and session; it is limited to a specified table. ident_current returns the value generated for a specific table in any session and any scope. For more information, see .
Scope_identity and @ identity return the last identity values that are generated in any table in the current session. however, scope_identity returns values inserted only within the current scope; @ identity is not limited to a specific scope.
For example, there are two tables,T1AndT2, And an insert trigger is defined onT1. When a row is insertedT1, The trigger fires and inserts a row inT2. This scenario extends strates two scopes: The insert onT1, And the insert onT2By the trigger.
Assuming that bothT1AndT2Have identity columns, @ identity and scope_identity will return different values at the end of an insert Statement onT1. @ Identity will return the last identity column value inserted into SS any scope in the current session. This is the value inserted inT2. Scope_identity () will return the identity value inserted inT1. This was the last insert that occurred in the same scope. the scope_identity () function will return the null value if the function is invoked before any insert statements into an identity column occur in the scope.
Use adventureworks; goselect ident_current ('Person. Address') As current_identity; go