Home Forums SQL Server 2005 Administering Get rid of duplicate records in a table using SQL Server 2005 RE: Get rid of duplicate records in a table using SQL Server 2005

  • First, there isn't a difference between the versions of SQL2000 or SQL2005 when it comes to PK's, or Unique index. The difference is how the objects were created in SQL2005.

    From what I understand, now when you insert a record you are getting a "cannot insert duplicate record in object xxx" error and a rollback occurs, which is the correct behavior when you have a unique index, or PK.

    The question is why are you inserting a duplicate record?

    Are you trying to "cleanup" the duplicate records? If so, the above links will help with that.

    Would you want to update the record instead, or are you always inserting?

    What about logic such as:

    If exists (select 1 from tablex where uniquekey = @uniquekey)

    begin

    update tablex set ....

    end

    else

    begin

    INSERT into tablex ...

    end