Posted on 2007-08-08
Medium Priority
Last Modified: 2008-02-01

Can anyone tell me or point me to any theory that using SCOPE_IDENTITY is isolated to the user who is performing the action, i.e. separate thread?. i.e. so If I call SCOPE_IDENTITY I will  get the value I require from the correct INSERT and not one that may have happened after my insert but before it executes the SCOPE_IDENTITY

Thanks in advance

Question by:REA_ANDREW
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 2000 total points
ID: 19653768
yes, SCOPE_IDENTITY() is doing exactly that: it gives you the identity value of YOUR scope (and session).

-> will give the same results, except if you have a trigger on the table that itself inserts to another table with identity
-> will give the current identity of the table, ignoring the scope (so would give you the identity generated by other users eventually)

LVL 20

Author Comment

ID: 19653833
excellent cheers.


Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question