How to delete duplicate record in sql server

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

Leave a Reply

Your email address will not be published. Required fields are marked *