SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Yet Another Deleting Duplicate Records (in-place)

By Peter Petrov,

Here is another "deleting duplicate records" script, this time in-place. It exploits the ability to relatively easily add and drop a uniqueidentifier column to a table. The term "must-be-unique columns" refers to the set of columns that have to have a unique combination of values (natural primary key candidate for the table). The DELETE statement is quite generic and the comments suggest the changes needed for any other table. In addition, you obviously have to replace "MyTab" with the name of your table.

Note: The "DELETE" statement is designed and formatted in order to extend its usage - replacing "DELETE t" with "SELECT t.*" will return the records that will be deleted.

Total article views: 1893 | Views in the last 30 days: 1
Related Articles

delete table



Delete Duplicates from table with no identity column

delete duplicates from table with all columns with datatype varchar()


How to delete first couple of rows without knowing column name

delete first 10rows from the table without knowing column names



Deletion of records


how can i avoid a column in a table from getting deleted?

how can i avoid a column in a table from getting deleted?

sql server 2005    
sql server 7