Delete Duplicate Records

replace "UniqueFields", "PK", and "table", then run Source: Halo_Four @ #SQL (EfNet)
Language:
T-SQL
Keywords:
Code Snippet

WITH dupes AS
    (SELECT ROW_NUMBER()
       OVER (PARTITION BY uniquefields ORDER BY pk) AS rownum
          , *
       FROM table)
DELETE FROM dupes WHERE rownum > 1;


Created 2012-01-25
comments powered by Disqus
Login