views:

350

answers:

2

Which should i use to get last inserted record id in sql server 2005?

I searched stackoverflow and i found this,

http://stackoverflow.com/questions/45651/sql-how-to-get-the-id-of-values-i-just-inserted

Comment of the best answer:

there are known bugs with SCOPE_IDENTITY() in sql server 2005, not sure about 2008, the OUTPUT clause can return a set of IDs if necessary...

Select SCOPE_IDENTITY() as Id from Table

I am uisng sql server 2005... Any suggestion

A: 

Triggers

Using @@identity is reliant on the fact that there are no triggers in your database creating records elsewhere.

If you create a record but a trigger then creates a log entry for the creation, @@identity will return you the id of the log entry in the log table.

Jon Winstanley
A: 

I'm not entirely sure what these "knows bugs" in SCOPE_IDENTITY() should be. The only thing I'm currently aware of is here: Six reasons you should be nervous about parallelism mentioned as the very first point.

Frank Kalis
https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=328811
KM
Ah, okay. Same one as in my link. :-)
Frank Kalis
fyi, that link is the #6 google result for **scope_dientity bug**
KM