Delete Duplicate Records From A Table



TODO:

Have you ever wanted to remove duplicate entries from a table using T-SQL?

 

SOLUTION:

 

BEGIN TRANSACTION

Delete from MyTable where row_id <
(Select Max(row_id) from MyTable mt where MyTable.Keywords = mt.Keywords)

--Verify data, then un-comment the commit
--COMMIT

 

 

NOTES:

This example deletes rows with duplicate 'Keywords' data.  'Keywords' is my column name.



Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading