如何检测SQ​​L Server表中的重复行?

Baj*_*jji 37 sql-server rdbms

检测10列/ 50K行表中重复项的最有效方法是什么?我正在使用MSSQL 8.0

kni*_*hor 57

举例说明其他人的描述:

SELECT
    Col1, -- All of the columns you want to dedupe on
    Col2, -- which is not neccesarily all of the columns
    Col3, -- in the table
    Col4,
    Col5,
    Col6,
    Col7,
    Col8,
    Col9,
    Col10
FROM
    MyTable
GROUP BY
    Col1,
    Col2,
    Col3,
    Col4,
    Col5,
    Col6,
    Col7,
    Col8,
    Col9,
    Col10
HAVING
    COUNT(*) > 1
Run Code Online (Sandbox Code Playgroud)


Gug*_*uge 13

您可以在所有列上使用"分组依据",然后计算(*)> 1

  • 这很有效,只要记住排除合成PK(如果有的话) (2认同)

Cha*_*ana 7

试试这个

Select * From Table
Group By [List all fields in the Table here]
Having Count(*) > 1
Run Code Online (Sandbox Code Playgroud)