what is the difference between SCOPE_IDENTITY() and @@IDENTITY in sqlserver ?


SCOPE_IDENTITY():

SCOPE_IDENTITY() to return the identity of the recently added row in your INSERT SQL Statement or Stored Procedure.

If we our requirement is to take the latest added row from table then we should have to use

SCOPE_IDENTITY()

@@IDENTITY:

It returns the most recently created identity for your current connection. It may not be  the identity for the recently added row in a table.

So it will be better to use SCOPE_IDENTITY() to fetch the latest row added in table.

If you know any more difference then please share with me.

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

%d bloggers like this: