On Thu, 2004-03-11 at 10:35, Jeff Garza wrote:
> Be carefull using @@IDENTITY, as it can return erroneous information (especially if your tables have triggers associated with them).  If you are using SQL Server 2000, use the SCOPE_IDENTITY() function instead of @@IDENTITY.

It doesnt return erroneous information - you just have to know how it
works. I have never had a problem with it, but I guess thats because I
knew the rule. @@identity returns the last inserted columns identity
within the transaction - key being on the last inserted - no matter
where the insert took place. I'd never heard of scop_identity() till
just now, but that sounds like a nice function - thanks Jeff

"... @@Identity returns the most recently created identity for your
current connection. When you first use it, it might be fine. Until
someone adds a trigger. If the trigger causes another identity to be
created, guess which identity you'll get in your call to @@Identity? Not
nice.

scope_identity() is much nicer. It gives you what you're expecting.�

http://weblogs.asp.net/rosherove/archive/2003/11/13/37217.aspx

--
Rob <[EMAIL PROTECTED]>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to