MS SQL Azure – T SQL to Delete duplicate records

Useful where you are importing data and you wish to remove any duplicates you might have imported. PKID is your identity index and keyval is the identity from the imported source. Adjust as appropriate

WITH cte AS (
  SELECT *, ROW_NUMBER() OVER (PARTITION BY keyval ORDER BY pkid) AS rn
  FROM dbo.t051
)
DELETE FROM cte WHERE rn > 1;