Thu 31 Jan 2002
NEW T-SQL technique! (or new to me). The @@IDENTITY function has historically been flaky and susceptible to outside interference. You must use it immediately after you do an insert if you want it to have the correct value, but even then, it can be clobbered by triggers that may have run in the meantime. The T-SQL SCOPE_IDENTITY function and the IDENT_CURRENT have
SCOPE_IDENTITY
IDENT_CURRENT
Returns the last identity value generated for a specified table in any session and any scope.
Special thanks to Rick Dilling for using this technique in a stored procedure I was reading. I haven't been able to confirm that this was added with SQL 2000, but it probably was.
Leave a Reply
You must be logged in to post a comment.



