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

  • One way this can be achieved is to put the rows to insert into a temporary table and then select from the temporary table only the rows that do not exist in the table where you want to insert the data finally.

    Step 1: Select all rows to insert into myTblModels

    Step 2: Select from myTblModels where row does not exists in final table.Insert these rows into final table:

    Insert into tblModels(column1,column2,....)

    Select *

    From myTblModels t

    Where Not Exists(Select 1 From tblModels f Where t.key1 = f.Key1 and t.Key2 = f.Key2.....)