Groups | Blog | Home
all groups > sql server (alternate) > april 2004 >

sql server (alternate) : Inserting row and scope_identity()


Marcus
4/30/2004 4:49:14 PM
With a query such as,

SET NoCount ON
INSERT INTO ....
VALUES ...
SELECT scope_identity()
SET NoCount OFF

, can I trust that the id I get back is for the row that I just inserted, or
can it be incorrect because of other "simultaneous" inserts? I need it for
an ASP page.

Thanks,
Marcus


Erland Sommarskog
4/30/2004 10:16:51 PM
[posted and mailed, vänligen svara i nys]

Marcus (lumbus@ludd.luth.se) writes:
[quoted text, click to view]

800 grader, du kan lita på mej, du kan lita på mej.

Yes, you can trust it. scope_identity is local to your process - in
fact local to the scope (procedure, batch etc) you are in.

--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
Marcus
5/4/2004 6:00:26 PM
Tack så mycket - Thank you. ;)

Marcus

[quoted text, click to view]


AddThis Social Bookmark Button