Header Ads Widget

Delete Duplicate Data From Database

There may be many duplicate data in database so we need to delete it. But remember we have to keep one row of same data other wise it would be deteletd  and we can not find any data which deleted
Delete Duplicate Data From Database
Delete Duplicate data from database and keep one record in Sql Server we need to have one primary key record and need to partition table using row number

WITH tblTemp as
SELECT ROW_NUMBER() Over(PARTITION BY [column name ]ORDER BY [column Name])
   As RowNumber,* FROM [TableName]
DELETE FROM tblTemp where RowNumber > 1

ROW_NUMBER() return the row of the grid. Here first we organized all data on sequence and from this we going to delete same data by keeping one data one top 
Here Don't change the other. change to column name by your desire or need delete data. and change the table name by your table

Post a Comment