1) FIRST METHOD
delete from TABLE NAME where id in(select MIN(id) from counter group by cid,ccounter)
2) SECOND METHOD
WITH DuplicateRecords AS
(
SELECT *,row_number() OVER(PARTITION BY cid,ccounter ORDER BY cid) AS RowNumber FROM counter
)
DELETE FROM DuplicateRecords WHERE RowNumber>1
How To Reset Identity Column In Sql Server Table To Start Auto Increment Or Seed From Desired Number
DBCC CHECKIDENT('YouTableName', RESEED, 0)
Delete duplicate records/rows by creating identity column.
alter table TABLE NAME add id int identity(1,1)delete from TABLE NAME where id in(select MIN(id) from counter group by cid,ccounter)
2) SECOND METHOD
Delete duplicate records using Row_Number()
WITH DuplicateRecords AS
(
SELECT *,row_number() OVER(PARTITION BY cid,ccounter ORDER BY cid) AS RowNumber FROM counter
)
DELETE FROM DuplicateRecords WHERE RowNumber>1
How To Reset Identity Column In Sql Server Table To Start Auto Increment Or Seed From Desired Number
DBCC CHECKIDENT('YouTableName', RESEED, 0)
No comments:
Post a Comment