Created
June 14, 2015 13:57
-
-
Save clintmjohnson/44f63ef816903d3b2751 to your computer and use it in GitHub Desktop.
Delete Duplicate Key Id Values on a SQL Server Table One by One
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE TableName | |
MERGE TOP (1) Product_Master_Table AS a | |
USING | |
(SELECT model_number,COUNT(*) AS dupeCount | |
FROM Product_Staging_Table | |
WHERE model_number <> '' AND model_number IS NOT NULL | |
GROUP BY model_number | |
HAVING COUNT(*) > 1) AS b | |
ON a.model_number = b.model_number | |
WHEN MATCHED | |
THEN DELETE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment