Sql server 2005: is it safe to use @@ identifier?

I have a procedure in which I insert an entry into the employee.nad table, getting empid using id @@? when this procedure is called by more than one user at the same time, it may be possible that it will return the identifier of some other employee inserted at the same time. Because there is no lock for system identification?

- code - Identification for the empirical column is
inserted into the value employee (name) ('sahil'); return @@ identity

refer to sql server 2005: Is it safe to use an identifier @@? to block identification problems

+3
source share
2 answers

Instead, you should use SCOPE_IDENTITY (). However, @@ IDENTITY refers to the current connection, so other users will not influence you, but there are other issues to consider.

More details here .

+8
source

@@ identity is unsafe. If the table has a trigger with an insert in the differnt table with an identifier, which is the value to be returned. Never use it to get the value of the inactivity you just inserted. You might think that I don’t have a trigger right now, but you never know when it can be added, and you can wait a long time before realizing that your data is hopelessly mixed up.

+3

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


All Articles