SELECT DISTINCT * INTO #T FROM TABLENAME
GOTRUNCATE TABLE TABLENAME
GOINSERT TABLENAME 
SELECT * FROM #T
GODROP TABLE #T
GO小心

解决方案 »

  1.   

    如果要删除重复记录,请参见:--刪除重復列
    a.如果有ID字段,就是具有唯一性的字段delect table where id not in (select max(id) from table group by col1,col2,col3...
    )
    group by 子句后跟的字段就是你用到判斷重复的字段b.,如果是判斷所有字段
    select * into #aa from table group by id1,id2,....
    delete table table 
    insert into table 
    select * from #aac.如果表中有ID的情況select identity(int,1,1) as id,* into #temp from tabel
    delect # where id not in (
    select max(id) from # group by col1,col2,col3...)
    delect table
    inset into table(...)
    select ..... from #temp
    col1+','+col2+','...col5 組合主鍵
    select * from table where col1+','+col2+','...col5 in (select max(col1+','+col2+','...col5) from table 
    where having count(*)>1
    group by col1,col2,col3,col4 
    )
    group by 子句后跟的字段就是你用到判斷重复的字段d.
    select identity(int,1,1) as id,* into #temp from tabel
    select * from #temp where id in (
    select max(id) from #emp where having count(*)>1 group by col1,col2,col3...)e.
    alter table yourtable add rownum int identity(1,1)
    go
    delete from yourtable where rownum not in (select min(rownum ) from yourtable group by 你重复的字段名)
    go
    alter table yourtable drop column rownum
    gof.
    alter table 表 add newfield int identity(1,1)
    delete 表
    where newfield not in(
    select min(newfield) from 表 group by 除newfield外的所有字段
    )alter table 表 drop column newfield
    g.
    -- 刪除表中重復的記錄
    DELETE delete1
    FROM tabTest delete1
    JOIN tabTest delete2 
    ON delete1.student_id=delete2.student_id AND delete1.course_id=delete2.course_id AND delete1.id>delete2.id
      

  2.   

    服务器: 消息 8163,级别 16,状态 3,行 1
    不能以 DISTINCT 方式选择 text、ntext 或 image 数据类型。
      

  3.   

    头疼,又是text、ntext 或 image 数据类型,长么,不长用cast转成字符,再用上面的方法
      

  4.   

    有一列id,int型,如果有两个或两个以上,保留一个所在的行。删除其他行。对于我的表这个也行
      

  5.   

    服务器: 消息 306,级别 16,状态 2,行 1
    不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符。
      

  6.   

    alter table rooms add [idx] int  identity(1,1) --加identity字段--取出不重复的方进另一个表或虚拟表
    select a.* into rooms2  from rooms a ,(select id,min(idx) idx from rooms group by id) b
    where a.id=b.id and a.idx=b.idx--删除原表
    drop table rooms--重命名新表
    EXEC sp_rename 'rooms2', 'rooms' --删除identity字段
    alter table rooms drop column idx
      

  7.   

    谢谢:lynx286() 可以实现了。但是数据量比较大105w,大家有没有更好的方法?
      

  8.   

    --加identity字段
    alter table rooms add [idx] int  identity(1,1)
    --删除重复行
    delete a from rooms a join rooms b on a.id=b.id and a.idx>b.idx
    --删除identity字段
    alter table rooms drop column idx