Aye, you'll want to do SCOPE_IDENTITY() 95% of the time.  And only do
the other 5% if you know why you're doing it that way :).

@@Identity looks across all tables, so if your insert has fired a
trigger that inserts into another table, you'll get the identity from
the second table (that the trigger inserted into), not the first. 
Oops!

There's also IDENT_CURRENT(tablename) which looks tempting because it
"returns the identity of the last row enterered into the specific
table."  This should probably be avoided in a multi-user system, as
it's possible for someone to do another insert between your INSERT
statement and SELECT IDENT_CURRENT(tablename) AS... statement.

-joe


On Fri, 10 Dec 2004 16:51:04 -0400, Kwang Suh <[EMAIL PROTECTED]> wrote:
> It has nothing to do with threads; rather if there's a trigger on the table, 
> the trigger might result in you getting the incorrect ID.
> 
> Always use SCOPE_IDENTITY() if you're using SQL Server 2000.
> 
> Never use triggers if you need to use @@IDENTITY in SQL Server 7. :)
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Special thanks to the CF Community Suite Silver Sponsor - CFDynamics
http://www.cfdynamics.com

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:187163
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to