我有一个表格,是从另外一台电脑上的SQLSERVER数据库“备份-还原”过来的,发现表内每行信息出现两次,即重复出现,我想删除重复的一行,提示“键列信息不足或不正确,更新影响到多行”,而不能删除,是什么原因啊?而同时还原过来的其他表格均没有这个问题,都很正常。

解决方案 »

  1.   

    sql server删除或修改记录时, 
    要以某个关键字为参考, 
    你的表可能没有设置关键字加入自增关键字,按关键字删除。
      

  2.   

    是不是出现好多数据完全一样的重复数据?
    用语句删除
    select distinct * into #t from tb
    truncate table tb
    insert into tb select * from #t
    drop table #t
      

  3.   


    alter table temp add ID int identity(1,1)delete a from temp a
    where ID not in (select min(ID) from temp where other_col = a.other_col)
      

  4.   

    1、在表里添加唯一索引;   
    2、若用到触发器、存贮过程则加一句"set   nocount   on"
      

  5.   

    with cte as(select * ,ROW_NUMBER() over(PARTITION by 所有列 order by getdate()) as rn from tb)delete from cte where rn=1