Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 @@IDENTITY Question

Author  Topic 

SamC
White Water Yakist

3467 Posts

Posted - 2002-09-23 : 10:44:20
Our ASP / SQL applicaiton supports multiple administrators who can add users one at a time. The ASP page calls a SQL procedure to insert a user, something like...

CREATE PROCEDURE UserInsert
@Username varchar (100)
AS
INSERT Users (Username) VALUES (@Username)
RETURN (@@IDENTITY)

I see procedures coded like this frequently in textbooks, and @@IDENTITY defined as the most current row. I'm left wondering if @@IDENTITY could get involved in a race condition when two Administrators add users at the same time. Does this procedure's executable statements need to be wrapped in Transact SQL to ensure @@IDENTITY points to this Administrator's record???

Sam

nr
SQLTeam MVY

12543 Posts

Posted - 2002-09-23 : 11:01:24
Nope. @@identity is the last identity allocated for that spid so what other admins are doing doesn't affect it..

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2002-09-23 : 11:18:38
Thanks..

Sam

Go to Top of Page
   

- Advertisement -