April 19, 2010 at 7:34 am
nigel. (4/19/2010)
This is how I interpret the docs:SCOPE_IDENTITY will return the identity value from the most recent insert in the current scope. If the most recent insert was to a table that has no IDENTITY column then the value returned by SCOPE_IDENTITY will be NULL.
Hi Nigel,
While that is, obviously, exactly what SCOPE_IDENTITY does, it is absolutely NOT what Books Online says, and there is no way you can interpret the text in Books Online that way.
This is exactly why I recommended Andrew to file this as a bug on the Connect site. Microsoft can then decide whether this is a documentation bug or a product bug, and fix either the docs or the product.
April 19, 2010 at 9:12 am
Hugo,
Thanks for the input.
Which would you say is correct, the implementation as it stands or BOL?
April 19, 2010 at 9:17 am
I just tried it in SQL2000 (my original attempt was in 2008), and it does the same, so I'd guess this is what is meant to happen, and it's probably BOL at fault (or it's a really old bug).
April 19, 2010 at 9:49 am
Thanks for the Question
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 19, 2010 at 11:04 am
nigel. (4/19/2010)
Hugo,Thanks for the input.
Which would you say is correct, the implementation as it stands or BOL?
Hi Nigel,
Tough question. We can't really look in the minds of the developers who originally wrote the feature, so we can only speculate.
And frankly, I see little reason to do an INSERT with an IDENTITY, and then first do another INSERT before testing SCOPE_IDENTITY, so I really would not mind much if Microsoft decides to change the docs, not the implementation. Given the similarlty to @@IDENTITY pointed out elsewhere in this discussion, that might very well even be the originally intended behaviour.
April 19, 2010 at 3:33 pm
An excellent question! - Thank you!
April 19, 2010 at 3:49 pm
You're welcome! It gave me a headache one day trying to debug an application, so I thought I'd post the question.
I've learned a great deal from this forum. It's amazing to me how even a simple question can generate a great discussion. That's why I keep coming back.
April 19, 2010 at 10:20 pm
Given the number of inconsistencies and bugs, I'd be quite happy to see @@IDENTITY and SCOPE_IDENTITY removed from the product. I very much prefer the OUTPUT clause for this purpose.
April 20, 2010 at 1:59 am
Hugo Kornelis (4/19/2010)
Tough question. We can't really look in the minds of the developers who originally wrote the feature, so we can only speculate.
Very true
And frankly, I see little reason to do an INSERT with an IDENTITY, and then first do another INSERT before testing SCOPE_IDENTITY, ...
Yes, it is a strange thing to do in the first place.
Given the similarlty to @@IDENTITY pointed out elsewhere in this discussion, that might very well even be the originally intended behaviour.
Agreed, given that the documentation for @@IDENTITY is quite clear on this it's odd (at the very least) that it's not covered in the SCOPE_IDENTITY docs.
June 10, 2010 at 1:52 am
nice question
Viewing 10 posts - 16 through 24 (of 24 total)
You must be logged in to reply to this topic. Login to reply