使用SQL Server Management Studio 2017。 我导入了大约2000万封电子邮件的列表,只需运行以下代码即可删除任何重复项:
WITH CTE AS
(
SELECT *,ROW_NUMBER() OVER (PARTITION BY email ORDER BY email) AS RN
FROM dbo.cleanemails
)
DELETE FROM CTE WHERE RN<>1
它表示查询已成功执行,并且在“消息”选项卡下显示受影响的1000万行(预期),但没有“结果”选项卡。 我想导出到csv文件。 我已经检查了执行设置,因为Parseonly和Noexec设置有时会导致问题,但它们都是OFF。
答案 0 :(得分:5)
如果要查看已删除的记录,则可以使用OUTPUT
子句
;WITH CTE
AS (SELECT *,
Row_number()OVER (PARTITION BY email
ORDER BY email) AS RN
FROM dbo.cleanemails)
DELETE FROM CTE
output deleted.*
WHERE RN <> 1