Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SCOPE_IDENTITY

Posted on 2006-07-17
2
Medium Priority
?
393 Views
Last Modified: 2008-03-17
I have a question about MS SQL Servers SCOPE_IDENTITY  -   this is the explanation MSDN gives:

SCOPE_IDENTITY returns the last identity value generated for any table in the current session and the current scope.

Can someone provide a brief explanation on what current session and current scope means?

I just want to be **guaranteed** that I will get the right value if I say:

SqlCommand comm ....

comm.CommandText = "INSERT INTO ..... ; SELECT SCOPE_IDENTITY()"
......

even if there are other connections to this DB going on in other currently running applications.
0
Comment
Question by:ARACK04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
athapa earned 1000 total points
ID: 17127294
If you have multiple applications (or instance or thread) which are inserting data into your server then you should use Scope Identity. If you just use identity then it may pick up the last identity value inserted into the database. However scope identity will return the last identity value generated by your session so it will be guarented to return you the last one you inserted.

AT
0
 
LVL 13

Assisted Solution

by:BlackTigerX
BlackTigerX earned 1000 total points
ID: 17128004
"even if there are other connections to this DB going on in other currently running applications"
yes, you will get the right value using scope_identity()
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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