select distinct * into #t from 原表
delete from 原表
insert 原表 select * from #t
drop table #t

解决方案 »

  1.   

    ALTER TABLE t ADD COLUMN id int identity (1,1)
    delete t where id in (select max(id) from t group by a1,b1,c1 having count(*)>1)
    --这一语句连续执行几次,直到影响的行数为0
      

  2.   

    select distinct * into #t from 原表
    truncate table 原表
    insert 原表 select * from #t
    drop table #t
      

  3.   

    谢谢各位高手  我还想知道 能不能用一个select语句 就能写出来的
      

  4.   

    可以是可以,但效率不是很高。
    ALTER TABLE t ADD COLUMN id int identity (1,1)
    delete t where not id in (select max(id) from t group by a1,b1,c1)
      

  5.   

    ALTER TABLE t ADD COLUMN id int identity (1,1)
    delete t where not id in (select max(id) from t group by a1,b1,c1)
    这也不是一句sql,
      

  6.   

    --ALTER TABLE t ADD COLUMN id int identity (1,1)
    这一句是加一个自动编号字段的。
    原来应该有一个自动编号字段,有就不用加了。
      

  7.   

    好像沒有辦法寫成一條語句了,你在中間加上union all 這樣的話一次就執行了。
      

  8.   

    windindance(风舞飞扬)方法确实不错!有一定的通用性!