April 24, 2013 at 7:04 am
Great question and very well written. I kind of figured the IDENTITY_INSERT was more for ease of confusion reasons than anything rather than assuming it was off.
April 24, 2013 at 7:57 am
Hugo Kornelis (4/24/2013)
Very good, and very clever question. Well done! 😉
I will totally second this statement. I sat there staring at the question...
I could rule out row one because it references row 2, which didn't exist yet
Row 2... referenced row 1... which the identity was used up due to the failed insert, but the failed insert meant that it too would fail
Finally row 3... was sneaky... ultimately I "went with it" and decided that it would insert... In all of what I've done, I've never tried to insert into a self referencing table a row that references itself, but I could see where that might be necessary (making the CEO report to himself in the company hierarchy instead of setting the identity of the employee he reports to, to null for example).
Thanks for making my brain have to work this morning!
April 24, 2013 at 8:44 am
Thank you all for your comments. I am glad to hear you liked the question, as this is first time I am posting one. Idea for this came up after a similar question couple of weeks ago, so thanks to that poster as well.
_______________________________________________
www.sql-kefalo.net (SQL Server saveti, ideje, fazoni i fore)
April 24, 2013 at 9:12 am
nenad-zivkovic (4/24/2013)
Thank you all for your comments. I am glad to hear you liked the question, as this is first time I am posting one. Idea for this came up after a similar question couple of weeks ago, so thanks to that poster as well.
Superb question. Please consider submitting more.
April 24, 2013 at 9:19 am
I too got it right for the wrong reason, thinking the second insert was the one that succeeded.
April 24, 2013 at 9:45 am
Excellent question. Drives home the point that, even if an insert fails on a table with an identity column, the identity value is 'consumed'.
Well done.
Rob Schripsema
Propack, Inc.
April 24, 2013 at 10:01 am
Rob Schripsema (4/24/2013)
Excellent question. Drives home the point that, even if an insert fails on a table with an identity column, the identity value is 'consumed'.Well done.
Agreed! +1
Not all gray hairs are Dinosaurs!
April 24, 2013 at 10:09 am
Really excellent question with a good clear explanation. More like thios onme, please!
Tom
April 24, 2013 at 12:07 pm
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 24, 2013 at 12:31 pm
Great question..
Thanks..
April 24, 2013 at 2:19 pm
Great question thanks
April 24, 2013 at 2:32 pm
Great question.
Love it.
April 25, 2013 at 2:01 am
This was removed by the editor as SPAM
April 25, 2013 at 10:09 am
Stewart "Arturius" Campbell (4/25/2013)
Excellent question, thanks.
+1
April 25, 2013 at 11:11 am
Nice question, thanks.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
Viewing 15 posts - 16 through 30 (of 35 total)
You must be logged in to reply to this topic. Login to reply