Home > Archive > MS SQL Server > February 2006 > Last iserted ID - MsQL









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Last iserted ID - MsQL
Tom

2006-02-04, 9:23 am

Is there any solution? Do you know some and would like to share? Please
Tom


Tom

2006-02-04, 9:23 am

Ok, I've found : @@IDENTITY


Jens

2006-02-04, 9:23 am

Hi, you may use the @@identity, but keep in mind that this is the
identity across all connections. Therefore if user 1 inserts a row and
a identity is given for this row, after this user2 inserts a rows and
after this user1 is querying the @@identity value, he will see the
Identity from user2. See the BOl for more information:

"@@IDENTITY and SCOPE_IDENTITY 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."

HTH, jens Suessmeyer.

Tom

2006-02-04, 1:23 pm

Thanks!


Michael Abraham

2006-02-04, 8:23 pm

Jens:

I believe that @@IDENTITY and SCOPE_IDENTITY are both limited to the current
connection, so, in your example, anything user2 does on a different
connection will not affect either @@IDENTITY or SCOPE_IDENTITY . The reason
to use SCOPE_IDENTITY is that it is not affected by anything that happens in
triggers that run as a result of the INSERT.

Mike A.
"Jens" <Jens@sqlserver2005.de> wrote in message
news:1139061571.055706.227700@g44g2000cwa.googlegroups.com...
> Hi, you may use the @@identity, but keep in mind that this is the
> identity across all connections. Therefore if user 1 inserts a row and
> a identity is given for this row, after this user2 inserts a rows and
> after this user1 is querying the @@identity value, he will see the
> Identity from user2. See the BOl for more information:
>
> "@@IDENTITY and SCOPE_IDENTITY 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."
>
> HTH, jens Suessmeyer.
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com