Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
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)

DeDuping Tables with Duplicate Records

By yomi_obe,

The script is in three parts:
1. A select statement to determine the number of duplicate records contained within the table
2. The deduping process builds a temporary table called #Duplicates and uses it to compare duplicates across both similar tables whilst deleting records with multiple counts
3. Final test of deduping with no records indicating table is clean of duplicates

The script is run against the database with the duplicate table. Ensure the following is replaced with your objects:
DuplicateTable >>> Your Table
Column1,2,3,... >>> Your Column Names
REQUIRED - The table MUST have an Identity Column
TableID >>> Your Table Identity Column

Total article views: 354 | Views in the last 30 days: 6
Related Articles

duplicating records in same table for different key columns

duplicating records in same table for different key columns


getting duplicate records for a primary key column

getting duplicate records for a primary key column


Concatenate column(s) of a duplicate

Concatinating column(s) of duplicate records


Selecting first duplicate record

duplicate records


Removing Duplicate Records

How to remove duplicate records from a table.


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones