在写入数据时,写了2行相同的数据   e.g   col1   col2
-------------
 1      2
 2      3
 1      2这样的话   再进行其它操作就会报错怎么样才能删掉重复的行?  

解决方案 »

  1.   

    select distinct * into # from tb
    go
    truncate table tb
    go
    insert tb select * from #
    go
    drop table #
      

  2.   


    如果col1+col2都相同,则只能使用临时表了.
      

  3.   

    --------------删除所有重复记录delete a where col1 in (select col1 from a group by col001 having count(*)>1)------------------全部重复 保留一条数据,select * into #b from a ---备份truncate table #binsert into a
    select disitnct  * from #b
    ---------------某个字段重复,只保留一条数据库(用游标)-------------------------用游标过滤重复记录
    declare @aa varchar(60)
    declare www cursor for
    select h_name from join_product_ty_bf
    open www
    fetch next from www into @aa
    while(@@fetch_status=0)
    begin
    fetch next from www into @aa
    if exists
    (select h_name from join_product_ty_bf where h_name like @aa group by h_name  having count(*)>1)
    delete join_product_ty_bf where current of www
    end