Wednesday, April 02, 2008

SCOPE_IDENTITY() and @@IDENTITY

Note to self, always use SELECT SCOPE_IDENTITY() instead of SELECT @@IDENTITY. I knew this already but always forget which one I should be using.

http://codebetter.com/blogs/john.papa/archive/2006/04/07/142503.aspx

2 comments:

Владимир said...

I remember using IDENT_CURRENT http://msdn2.microsoft.com/en-us/library/ms175098.aspx instead of SCOPE_IDENTITY() because of lack of knowledge. It was live multi-user system I developed (http://www.cwwg.org/as01.24.03.html), and my mistake was discovered after part of the data of one user was added to another user... I was be able to find my error during the day...

Doogal said...

Thanks for the info, I wasn't even aware of IDENT_CURRENT! I'm sure that and @@IDENTITY probably have their uses, but I'm guessing SCOPE_IDENTITY() is the one to use 99% of the time