Why You Should Avoid Using the @@IDENTITY Function

Phil Factor demonstrates why SQL Prompt has a 'Best Practice' rule (BP010) that checks for use of the @@IDENTITY function and suggests less error-prone ways to get the latest identity values used in a table.

The @@IDENTITY function returns the last IDENTITY value created in the same session. If you have a trigger on the table or if the table is a publication in a replication, then the value can sometimes be wrong. SQL Prompt's BP010 code analysis rule will warn you if it detects its use in your SQL code.