Managing Sequential Values
There was a time when dealing with identity columns in triggers was a black art. You had to jump through numerous hoops to get identity columns to work properly, and even then there were situations when it wasn't airtight. Thanks to the addition of SCOPE_IDENTITY() and IDENT_CURRENT() to Transact-SQL, this is no longer the case. As its name suggests, SCOPE_IDENTITY() retrieves the current value for an identity column within the current scope. IDENT_CURRENT(), on the other hand, doesn't care about the current scope. It just returns the latest identity value inserted into a table. These are both better tools than the venerable @@IDENTITY function. @@IDENTITY returns the last identity value inserted for the current connection, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access