Skip to content

Instantly share code, notes, and snippets.

@djsipe
Created August 11, 2017 14:29
Show Gist options
  • Save djsipe/f26b8b4aeb1187f2d70ab817c27858dd to your computer and use it in GitHub Desktop.
Save djsipe/f26b8b4aeb1187f2d70ab817c27858dd to your computer and use it in GitHub Desktop.
Detect duplicates in a SQL table.
-- 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