The topic describes the DF008 T-SQL code analysis rule.
BEST PRACTICE
The @@IDENTITY function is used.
The @@IDENTITY function may return incorrect results. It is recommended to use the SCOPE_IDENTITY() function instead.
It is recommended to rewrite the stored procedure being called or Transact-SQL statement to use the SCOPE_IDENTITY() function. This function returns the most recent identity value generated within the scope of the user statement rather than the identity value within any nested trigger used by replication.
INSERT INTO dbo.Customers(FirstName, LastName) VALUES(@FirstName, @LastName)
SELECT @@IDENTITY AS CustomerID
INSERT INTO dbo.Customers(FirstName, LastName) VALUES(@FirstName, @LastName)
SELECT SCOPE_IDENTITY() AS CustomerID