In this article I will explain you how to delete duplicate record from SQL SERVER table. Sometime what happens we need to delete duplicate records from a table, but table doesn’t contain primary or unique key.
Let’s see how.
We have a table Salary in SQL Server.
CREATE TABLE SALARY
(EMPID INT ,
EMPNAME VARCHAR(50) NULL,
PAYMENT INT NULL)
SELECT * FROMSALARY
WITH DupRec
AS
(SELECT EMPNAME,ROW_NUMBER()
OVER (PARTITION BY EMPNAME ORDER BY EMPID)
RECORDDUP FROMSALARY)
DELETE FROM DupRec WHERERECORDDUP>1