Created
August 11, 2017 14:29
-
-
Save djsipe/f26b8b4aeb1187f2d70ab817c27858dd to your computer and use it in GitHub Desktop.
Detect duplicates in a SQL table.
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
-- SQL Server | |
IF EXISTS( | |
SELECT | |
row_identifier, | |
COUNT(*) | |
FROM table_to_check | |
GROUP BY row_identifier | |
HAVING COUNT(*) > 1 | |
) | |
BEGIN | |
RAISERROR('Duplicate record found.',16,1) | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment