Delete duplicate records using this script in MS Sql Server

Hi Friends ,

You can delete duplicate records using this script in MS Sql Server. I write a example below.


Declare @tblEmployee As table 
(
Eid int,
Ename varchar(10)
)  

insert into @tblEmployee values(1,'A')
insert into @tblEmployee values(2,'B')
insert into @tblEmployee values(3,'A')
insert into @tblEmployee values(4,'D')
insert into @tblEmployee values(5,'B')

Select * from @tblEmployee 

Delete From @tblEmployee Where Eid in (

Select Eid from 
(Select * , ROW_NUMBER() Over ( partition by Ename Order by Ename ) As ICount  From @tblEmployee )As Qry Where Qry.ICount > 1
)

Select * from @tblEmployee 






Comments

Popular posts from this blog

Find procedure and function in SQL Server

Windows Service Install and Un Install in MS VisualStudio 2010

Find Store Procedures and Functions in MS SQL Server.