February 2, 2012 at 4:25 am
Good Day . We ran a script to update a record in a table with a unique index . However we get the message that we tried to insert a duplicate record into the table . Any ideas how an update can be confused with an insert by SQL Server ?
February 2, 2012 at 5:18 am
If you have a unique index, it prevents duplicate data. It doesn't matter if you're updating to duplicate the data or inserting to duplicate the data. You can't have duplicate data.
----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software
February 2, 2012 at 8:31 am
Grant is exactly correct. You could also go with the fact that an update actually consists of a delete then an insert.
February 2, 2012 at 8:44 am
So, if you have 3 records with key values of 1, 2, 3. Then you try to change the 3 to a 1, you are attempting to create a duplicate 1.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply