How to Return the last-inserted identity value

@@IDENTITY, SCOPE_IDENTITY, and IDENT_CURRENT are similar functions in that they return the last value inserted into the IDENTITY column of a table.
 
@@IDENTITY and SCOPE_IDENTITY will return the last identity value generated in any table in the current session.
However, SCOPE_IDENTITY returns the value only within the current scope; @@IDENTITY is not limited to a specific scope.
Example :
INSERT INTO emp (Name,Dept,Desi)
VALUES (‘Sri’,1,3)
SELECT @@IDENTITY AS ‘Identity’
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s