Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 333 |  Welcome, Guest!   Register  Login
 Home > Forums > Sql Server > Scope Identity in SQL Server ...
Sridevi

Scope Identity in SQL Server

Replies: 12 | Posted by: Sridevi on 7/13/2012 | Category: Sql Server Forums | Views: 431 | Status: [Member] | Points: 10  


What is scope identity in SQL server? Could anyone explain me in detail?

Regards,
Sridevi

Sridevi


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Premalatha
Premalatha  
Posted on: 7/13/2012 12:10:58 PM
Level: Starter | Status: [Member] | Points: 25

Returns the last identity value inserted into an identity column in the same scope. A scope is a module: a stored procedure, trigger, function, or batch.

Premalatha
Software Engineer

Sridevi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Patel28rajendra
Patel28rajendra  
Posted on: 7/13/2012 2:22:25 PM
Level: Starter | Status: [Member] | Points: 25

Hi

It returns identity of Last Record Inserted in the table



R D Patel

Sridevi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Sgtammana
Sgtammana  
Posted on: 7/14/2012 3:40:27 AM
Level: Starter | Status: [Member] | Points: 25

Hi,
you will get the Latest identity value of the current scope which you are in.
for example:
if you are executing an SP. in that sp you had inserted a record in a table A and the identity value is 10 and also at the same time from the outside another user insert the record in the same table as 11.
if used the scope identity you will get the value as 10.

Tammana

Sridevi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

CGN007
CGN007  
Posted on: 7/15/2012 11:54:16 PM
Level: Silver | Status: [Member] | Points: 25

Sridevi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Hemanthlaxmi
Hemanthlaxmi  
Posted on: 7/16/2012 2:41:33 AM
Level: Starter | Status: [Member] | Points: 25

Hi Sridevi,

read this blog clearly exaplined about the Scope Identity

http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/

If this helps you .
Please "Mark as Answer"

Sridevi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Ranjeet_8
Ranjeet_8  
Posted on: 7/16/2012 2:53:31 AM
Level: Gold | Status: [Member] | Points: 25

Sridevi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Karthikeyanp365
Karthikeyanp365  
Posted on: 7/25/2012 12:57:34 AM
Level: Starter | Status: [Member] | Points: 25

SELECT @@IDENTITY
SELECT SCOPE_IDENTITY()

The above both sql query returns the last identity value entered into a table in your current session.

SELECT IDENT_CURRENT('tablename')
It returns the last IDENTITY value produced in a table

Sridevi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Bhupentiwari
Bhupentiwari  
Posted on: 7/25/2012 4:09:34 AM
Level: Starter | Status: [Member] | Points: 25

Sridevi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

CGN007
CGN007  
Posted on: 7/31/2012 6:12:55 AM
Level: Silver | Status: [Member] | Points: 25

Sridevi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

CGN007
CGN007  
Posted on: 7/31/2012 9:34:00 AM
Level: Silver | Status: [Member] | Points: 25

Mark as answer if it helps...,That motivates...!!!

Sridevi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Muhsinathk
Muhsinathk  
Posted on: 9/5/2012 12:33:12 AM
Level: Bronze | Status: [Member] | Points: 25

Hi,
SELECT SCOPE_IDENTITY()
It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.
SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.

Sridevi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Shanky11
Shanky11  
Posted on: 9/5/2012 12:55:04 AM
Level: Starter | Status: [Member] | Points: 25

Can u give some example?

Sridevi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/19/2013 6:23:44 AM