Pages

Sunday, August 12, 2012

Delete the duplicate records in the table

How to delete the duplicate records in the table of a SQL Server


Query to delete the duplicate records:


WITH CTE (COl1,Col2, DuplicateCount)
AS
(
SELECT COl1,Col2,
ROW_NUMBER() OVER(PARTITION BY COl1,Col2 ORDER BY Col1) AS DuplicateCount
FROM DuplicateRcordTable
)
DELETE
FROM CTE
WHERE DuplicateCount > 1
GO