--添加标识字段
alter table 表 add 标识字段 decimal(38,0) identity(1,1)
go--删除处理
delete 表
from 表 a left join(
  select name,标识字段=min(标识字段) from 表 group by name --假设以name字段判断是否重复
)b on a.标识字段=b.标识字段
where b.标识字段 is null
go--完成后删除标识字段
alter table 表 drop column 标识字段

解决方案 »

  1.   

    --如果你不愿意修改表结构,那就只好用临时表了(最低效的办法)--生成临时表
    select 标识字段=identity(decimal(38,0),1,1),* into #t from 表
    go--删除处理
    delete #t
    from 表 a left join(
      select name,标识字段=min(标识字段) from #t group by name
    )b on a.name=b.name and a.标识字段=b.标识字段
    where b.标识字段 is null
    go--删除处理完成后,删除临时表中的标识字段,方便数据导入
    alter table #t drop column 标识字段
    go--删除原表中的数据
    truncate table 表   --这样速度够快,如果不能用这句,改为: delete  表
    go--导回不重复的数据
    insert into 表 select * from #t
    go--删除处理的临时表
    drop table #t