June 15, 2010 at 7:20 am
I have a production table with Identity column and few databases are built with reference to this ID column but now i have to delete duplicates from this table but I might lose reference in other databses. What would be the best approach to handle this by deleting duplicates.
June 15, 2010 at 7:25 am
1. Identify duplicates.
2. For each duplicate, identify which one should be kept.
3. For each other table, update the duplicates with the value being kept.
4. Delete the duplicates.
I'd suggest a backup of the original data ... just in case.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
June 24, 2010 at 10:45 am
If possible, I'd also wrap any deletes in a transaction, along with a test to see if things work before you commit the transaction.
June 25, 2010 at 3:20 am
I guess that you're talking about a SQLServer-supplied auto-increment IDENTITY column?
If so, would now be a good time to discover the real key of the referenced table?
Otherwise, make sure you keep a copy of the clean-up process, so that you can use it next time you get duplicates, and the time after that, and... 🙂
June 25, 2010 at 6:27 am
i have some confusion here , if the column is identity--auto incremented then how duplicates records generated ?
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
June 25, 2010 at 9:17 am
The identity is not guarenteed to be unique. You can insert values into the identity column with SET IDENTITY_INSERT ON. They could possibly be duplicates.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply