Click here to monitor SSC
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)

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: 357 | Views in the last 30 days: 3
 
Related Articles
FORUM

duplicating records in same table for different key columns

duplicating records in same table for different key columns

FORUM

getting duplicate records for a primary key column

getting duplicate records for a primary key column

FORUM

Concatenate column(s) of a duplicate

Concatinating column(s) of duplicate records

FORUM

Selecting first duplicate record

duplicate records

SCRIPT

Removing Duplicate Records

How to remove duplicate records from a table.

 
Contribute