How to delete duplicates records in the SQL Server 2005/2008


Step 1. Login into SQL Server
Step 2. Run the following query
WITH CTE (Col1,Col2, DuplicateCount)
AS
(
SELECT Col1,Col2,
ROW_NUMBER() OVER(PARTITION BY Col1,Col2 ORDER BY Col1,Col2) AS DuplicateCount
FROM Table1
)
DELETE
FROM CTE
WHERE DuplicateCount > 1
where Col1 and Col2 are the composite key for the Table1.
Note - This query does not require that Table1 should contain a primary key or Identity column.
All queries are welcome !!