On a SQL Server 2005 database, one of our remote developers just checked in a change to a stored procedure that changed a ‘select scope_identity’ to ‘select @@identity’. Do you know of any reasons why you’d use @@identity over scope_identity?
Share
@@IDENTITYwill return the last identity value issued by the current session.SCOPE_IDENTITY()returns the last identity value in the current session and same scope. They are usually the same, but assume a trigger is called which inserted something somewhere just before the current statement.@@IDENTITYwill return the identity value by theINSERTstatement of the trigger, not the insert statement of the block. It’s usually a mistake unless he knows what he’s doing.