\insert Duplicate record

  • 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 ?

  • 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 Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Grant is exactly correct. You could also go with the fact that an update actually consists of a delete then an insert.

  • 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