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

解决方案 »

  1.   

    select distinct * into #t from 原表找出没有重复的记录,有重新的记录取一条distinct  .插入到临时表T中truncate 原表这里应该是删除原来的表吧insert into 原表 select * from #t把临时表的内容插入到原表drop table #t删除掉临时表==================================我解释下这个方法,我一般也这样做
      

  2.   

    delete a from tablename a 
    where exists (select * from tablename where key=a.key and id <a.id)如果tablename 没有id 字段:
    alter table tablename add id int identity(1,1)
    delete a from tablename a 
    where exists (select * from tablename where key=a.key and id <a.id)
    alter table tablename drop column id
      

  3.   

    DELETE FROM [表] WHERE id NOT IN (SELECT MIN(id) FROM [表] GROUP BY 重复字段1, 重复字段2, ...)
      

  4.   

    可以不用语句
    假设原来的表为TableA,Col1重复则为重复,需要保留一笔即可
    建立一张具有和TableA相同结构的表myTableA,单击鼠标右键,选择所有任务,选择管理索引,选择新建,起个索引名字,列就是Col1,建立一个索引,勾选上唯一(unique),勾选上忽略重复的值,其他不要选择!然后把资料insert into到表myTableA,
    此时SQL Server会返回如下提示:
      服务器: 消息 3604,级别 16,状态 1,行 1
      已忽略重复的键。
      它表明在表myTableA中不会有重复的行出现。然后将原表TableA清空,并将临时表myTableA中数据导入,最后删除临时表myTableA。
    这样就完成了对表中重复记录的删除。该方法的执行速度都是相当快的,而且因为几乎不用写语句,所以它也是很安全的。不过要依靠你的Col1,万一你操作不当,没有关系,不要那么急着删除原来的表,这样不会出什么异常,错删除纪录!该方法的好处是,速度非常快,尤其是数据多的时候,用distinct,或者identity的速度很慢,这个方法倒是出了大量的数据,速度方面表现不错