以前表中没有key,结果,输入了很多记录相同的纪录。现在想加key了,可是存在主键冲突问题。如何找出来?

解决方案 »

  1.   

    select [key]
    from test
    group by [key]
    having count(1)>=2
      

  2.   

    假设 a,b..是联合主键
    select * from yourTable A where (select count(1) from yourTable where a=A.a and b=A.b ..) > 1
      

  3.   

    不用这么复杂吧假设 a,b..是联合主键
    select a,b,count(*) as 记录数 from yourTable
    group a,b
    having count(*)>=2
      

  4.   

    Declare @Student Table(Id int,SName Varchar(10),Score Int)
    Insert @Student Select 1,'张三',69
    Union all Select 2,'李四',89
    Union all Select 3,'张三',69select * from @Studentdelete from @Student where id not in
    (
    select min(id) 
    from @Student 
    group by SName,Score
    )select * from @Student
      

  5.   

    上面是以前一个帖子的,
    像你的情况你可以生成一个临时表先select id=identity(int,1,1),* from yourtablename再对临时表进行处理