November 17, 2014 at 5:13 am
edwardwill (11/17/2014)
The update was incomplete as well. The requirement was to update two rows, so the SQL should have readSET IDENTITY_INSERT dbo.Roles ON
UPDATE dbo.Roles
SET RoleID=-3
WHERE RoleID=-2;
UPDATE dbo.Roles
SET RoleID=-2
WHERE RoleID=-1;
SET IDENTITY_INSERT dbo.Roles OFF
or something like that. Of course, the UPDATE was going to fail anyway, so the point is moot.
One UPDATE was enough for demo of the QotD.
Igor Micev,My blog: www.igormicev.com
November 17, 2014 at 5:40 am
Igor Micev (11/17/2014)
Why not?
No reason at all, I was just curious as to what scenario might require it 🙂
November 17, 2014 at 6:25 am
Really nice question. Good way to get the brain moving on a Monday morning.
November 17, 2014 at 6:43 am
This question was pretty simple for me... only because I tried this method of updating the primary keys late last week. My solution was no where even as sophisticated as the above solutions. 🙂
November 17, 2014 at 7:13 am
Good question, to remind us that allowing an arbitrary insert doesn't mean update too.
November 17, 2014 at 8:23 am
twin.devil (11/17/2014)
Igor Micev (11/17/2014)
The Question came as a real case experience with a software developer, and I had to do the update in that way, ... so thought to share it.Thanks.
+1000, So true and QotD is the best place to share it. 🙂
+1 Thanks for the great question.
November 17, 2014 at 8:36 am
Nice question, and it could be tricky for anyone that has manually updated an identity value through the GUI. I've done this on occasion and it's not apparent that a new table is actually being created in the background.
Aigle de Guerre!
November 17, 2014 at 10:06 am
Good Question and good answer. Thanks
Not all gray hairs are Dinosaurs!
November 17, 2014 at 1:30 pm
Great question, Igor, thanks.
November 18, 2014 at 4:50 am
Ok, good to know that, thanx.
Thanks & Best Regards,
Hany Helmy
SQL Server Database Consultant
November 18, 2014 at 11:04 pm
Hello Igor,
In the question, are you assuming the correct database has been selected from the drop down menu?
Thanks,
Tim
The pain of Discipline is far better than the pain of Regret!
November 19, 2014 at 5:11 am
Excellent Question! Thanks for sharing!
The SWITCH TO method to update identity column is new to me. Thanks for that too.
Viewing 12 posts - 16 through 26 (of 26 total)
You must be logged in to reply to this topic. Login to reply