@@ IDENTITY vs SCOPE_IDENTITY () vs IDENT_CURRENT [sql server 2005]

What should I use to get the last inserted record identifier in SQL Server 2005?

I searched for stackoverflow and found this,

SQL: How to get the identifier of the values ​​that I just INSERT?

Comment best answer:

there are known errors with SCOPE_IDENTITY () in sql server 2005, not sure in 2008, the OUTPUT clause may return a set of identifiers if necessary ...

Select SCOPE_IDENTITY() as Id from Table 

I am uisng sql server 2005 ... Any suggestion

+1
source share
2 answers

I'm not quite sure what this “knows errors” is in SCOPE_IDENTITY (). The only thing I know about right now: Six reasons why you should be nervous about parallelism , mentioned as the very first point.

0
source

Triggers

Using @@identity depends on the fact that there are no triggers in your database that create entries elsewhere.

If you create an entry, but the trigger then creates a log entry to create, @@identity will return you the log entry id in the log table.

+4
source

Source: https://habr.com/ru/post/1369121/


All Articles