The content is referenced from:
@ Identity, scope_identity and ident_current
Http://www.cnblogs.com/xlong1900/archive/2008/09/01/1281001.html
@ Identity, scope_identity and ident_current
Functions of @ identity, scope_identity and ident_current in sqlserver
Similarities:
Both return values inserted into the identity column..
Differences:
A.@ Identity is not restricted by the scope (stored procedures, triggers, functions, or batch processing. Returns the last inserted identity value.. If the table inserted in different scopes in the program is different, the identity value inserted in the last table is returned. For example, scope A inserts the identity column on table T1, while triggers on table T1 Insert the identity column on table T2. @ Identity is used to return the inserted identity value on T2.
B.Scope_identity () is restricted by scope. Only the last identity value in the current scope is returned.. In the above example, if scope_identity () is used in the stored procedure, return the identity value of T1.
C.Ident_current () is not restricted by the scope. When calling it, you must provide the unique parameter indicating the table name. You can get the last identity value of any table you want, even if there is no insert action in your code. For example: ident_current ( ' T1 ' );
Experience:
Select different functions based on different application scenarios. If a new piece of data is added to the table during the write stored procedure and this identity value needs to be returned, scope_identity () is used because it is associated with the current session, it does not return a value you do not need. If you only want to get the last value of an identity column, ident_current () is the most convenient.