--用临时表做暂存表,如:
select distinct * into #t from tblname
truncate table tblnameInsert into tblname
select * from #tdrop table #t

解决方案 »

  1.   

    方法1:
    --简单的方法就是借用临时表
    --方式:把数据首先放到临时表
    --在临时表中处理重复记录问题.
    --删除物理数据表
    --从临时表把数据取出来,放入物理表中
    --删除临时表
    Select distinct * into #temp from table1delete table1insert into table1
    Select * from #temp drop table #temp方法2:
    --方式2:
    delete 表名
    from 表名 tt
    where  exists(select 1 from 表名 where 字段=tt.字段 and 字段=tt.字段 and 主键<tt.主键)
    方法3
    --保留最小的ID
    delete 表 where ID not in(select min(ID) from 表 group by 字段...(注:重复的字段行))
      

  2.   

    楼主语法有问题 :请问如果删除同一个表中相同的记录吗???应该是请问如何删除。 SQL Server-----------------------------------------------------
      

  3.   

    看看这个~
    http://www.mscenter.edu.cn/laputa/article/2004-12/0/13/10318.xml
      

  4.   

    呵呵,不知道是不是把简单问题复杂化了:)
    楼主的意思是说把所有满足同一条件的记录全部删除吗?
    如果是,就如下:
    Select * from City where CityName='北京'
    楼上WangZWang(阿来) 的意思可能是说,还要保留一条记录、去除与其重复的记录的。
      

  5.   

    hellolongbin(一个人[终不似 少年游])
    兄弟,做人要厚道!
      

  6.   

    思路是这样,首先找出重复的记录,然后在临时表中分别删除重复的记录,再把临时表中的信息复制给原表.
    比如有记录字段code
    select code 
    into #temptable1
     from 表
    group by code
    having count(code)>1select IDENTITY(int,1,1) as '序号' ,表.* 
    into #temp表
    from 表delet from #temp表
    where code=#temptable1.重复字段
    and 
    序号 >
    ( select min(序号) from #temp表 
    inner join  #temptable1 on #temp表.code=#temptable1.code
    where #temp表.code=#temptable1.重复字段(从#temptable1取具体的值))
    注:这是一条一条删除的
    删除原来表中的信息
    然后把#temp表信息复制给原来的表
    最后drop table #temptable1 
    drop table #temp表
    如果重复的数据量少的话就这么偷懒做吧,呵呵,如果多的话就用游标循环处理