exec sp_dboption yourDBName,'select into/bulkcopy',true;
go
select distinct * into #temp from yourTable;
go
truncate table yourTable;
go
insert into yourTable select * from #temp;

解决方案 »

  1.   

    這真是一個很古老的問題,建議結帖後馬上整理到FAQ。
      

  2.   

    //清除重复数据
    select distinct * into #t1 from table1
    delete from table1
    insert into table1 (collist) select * from #t1
      

  3.   

    method 2:exec sp_dboption yourDBName,'select into/bulkcopy',true;
    go
    select distinct * into newTable from yourTable;
    go
    drop table yourTable;
    go
    exec sp_rename 'newTable','yourTable'
      

  4.   

    這真是一個很古老的問題,建議結帖後馬上整理到FAQ。
      

  5.   

    删除表中重复记录,(得出单一的记录)如下:--表定义
    create table abc (A char(2),B char(2),C char(2))--如下两条记录
    insert abc values("a1","b1","c1")
    insert abc values("a1","b1","c2")想得到如下结果a1,b1,c1
    SELECT A,B,MIN(C) From TableName GROUP BY A,B找出相同记录:
    SELECT A,B
    FROM abc
    GROUP BY [a], [a]
    HAVING Count([A])>1 And Count([A])>1
      

  6.   

    重復的數據可以用having來完成。
    select yourKey1,yourKey2.. 
            from yourTable 
            group by yourKey1,yourkey2.. 
            having count(oneofyourkey)>1
      

  7.   

    对不起!搞错了,应为:
    GROUP BY [a], [b]
    HAVING Count([A])>1 And Count([b])>1
      

  8.   

    结贴了,我补充一下,如果表里有DEFAULT等约束,用select ... into ...时会丢失这些约束,所以建议用以下方法:exec sp_dboption yourDBName,'select into/bulkcopy',true
    go
    select distinct * into newtable from tablename
    go
    truncate table tablename
    go
    insert tablename
    insert * from newtable
    go
    drop table newtable
    go
    --如果原来select into/bulkcopy设置为false
    --exec sp_dboption yourDBName,'select into/bulkcopy',false
    --go