Deleting duplicate records:
Self join the table on all the columns that can possibly have same values and differentiate b/w the duplicate values based on the identity column. In the provided script I've taken Employees table which has some duplicate rows. The duplicacy is possible on EmployeeNo and EmployeeId. Id is a Identity column. TO find and delete the duplicate records, I join the Employee table with itself on the non-unique columns, EmployeeNo and EmployeeId in this case.
The table in consideration must have at least one non-unique column. If a table does not have any identity column then there are two possiblities :
i. Use the get row_num sql-query in conjunction with this script in place of unique field.
* Create a copy of the table using:
Select * into EmployeesCopy from Employees where 1 = 0
* Alter table to add an identity column in it.
* Insert all records from Employees to EmployeesCopy.
* Delete duplicates using sbove script implementation
* Delete all records from Employees
* Copy the new contents from EmployeesCopy to Employees