i have a procedure in which i am inserting record in employee table.nad getting empid by using @@identity ? when this procedure will be called by more than one user at same time,there can be possibility that it returns identity of some other employee inserted at same time.because there is no lock on identity by system?
–code
–identity on for empid column
insert into employee (name) values (‘sahil’);
return @@identity
refer sql server 2005:is it safe to use @@identity?
for lock on identity issue
You should be using SCOPE_IDENTITY() instead. However, @@IDENTITY refers to the current connection so other users won’t affect you but there are other issues to consider.
More information here.