June 25, 2010 at 9:04 am
I avoid using @@IDENTITY in t-sql code because it can return unexpected values:
"It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value."
Do @@trancount and @@rowcount suffer from the same issue?
TIA,
Barkingdog
June 25, 2010 at 9:10 am
To my knowledge, no.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
June 25, 2010 at 9:11 am
@@Trancount returns the current transaction count for that connection.
@@rowcount returns the number of rows affected by the last statement that ran on that connection.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 25, 2010 at 9:25 am
Keyword here is connection. These are stable for the connection. @@identity doesn't scope to your connection or that table.
June 25, 2010 at 9:58 am
Steve Jones - Editor (6/25/2010)
Keyword here is connection. These are stable for the connection. @@identity doesn't scope to your connection or that table.
As usual, Pinal Dave has the 411!
[font="Courier New"]ZenDada[/font]
June 25, 2010 at 11:43 am
ZenDada (6/25/2010)
Steve Jones - Editor (6/25/2010)
Keyword here is connection. These are stable for the connection. @@identity doesn't scope to your connection or that table.
As usual, Pinal Dave has the 411!
What is the problem with Books OnLine ?
* Noel
June 25, 2010 at 11:49 am
noeld (6/25/2010)
ZenDada (6/25/2010)
Steve Jones - Editor (6/25/2010)
Keyword here is connection. These are stable for the connection. @@identity doesn't scope to your connection or that table.As usual, Pinal Dave has the 411!
What is the problem with Books OnLine ?
Not a blog. You miss out on all the fun of... "oh oh... look over there... no over there... there... wow that's cool!"
[font="Courier New"]ZenDada[/font]
June 25, 2010 at 1:09 pm
ZenDada (6/25/2010)
noeld (6/25/2010)
ZenDada (6/25/2010)
Steve Jones - Editor (6/25/2010)
Keyword here is connection. These are stable for the connection. @@identity doesn't scope to your connection or that table.As usual, Pinal Dave has the 411!
What is the problem with Books OnLine ?
Not a blog. You miss out on all the fun of... "oh oh... look over there... no over there... there... wow that's cool!"
Oh oh oh .... look is regurgitating what's already said in Books online ... I get it
* Noel
June 25, 2010 at 1:20 pm
Also, you can simply return the IDENTITY values inserted in the OUTPUT clause of the INSERT statement.
This is probably the best solution, and the only good solution for the case of a multi-row insert.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply