how to delete the duplicate rows from the table parmanently ?
Asked
Active
Viewed 59 times
-5
-
2I think you should clarify your question a bit with examples of what you have tried so far, and what output you are expecting. See [how to ask a question.](http://stackoverflow.com/help/how-to-ask) – Roman Marusyk Feb 03 '16 at 10:37
-
Use DELETE, and make sure the transaction is commited. – jarlh Feb 03 '16 at 10:38
1 Answers
2
I like CTE's and ROW_NUMBER since it allows to change it easily to see which rows are deleted (or updated), therefore just change the DELETE FROM CTE... to SELECT * FROM CTE:
;WITH CTE AS (
SELECT [col1],
[col2],
[col3],
[col4],
[col5],
[col6],
[col7],
RN = ROW_NUMBER() OVER (PARTITION BY col1 ORDER BY col1)
FROM dbo.table
)
DELETE FROM CTE
WHERE RN > 1
Try this