输出重复数据

 sql:

       select distinct * into #tmp from tablename

       drop table tablename

       select * into tablename from #tmp

       drop table #tmp

2.用游标进行删除

declare @max integer,@id integer 
declare cur_rows cursor local for select 主字段,count(*) from tablename group by 主字段 having count(*) > 1 
open cur_rows 
fetch cur_rows into @id,@max 
while @@fetch_status=0 
begin 
select @max = @max -1 
set rowcount @max 
delete from tablename where 主字段= @id 
fetch cur_rows into @id,@max 
end 
close cur_rows 
set rowcount 0

posted @ 2016-10-19 12:16  applekingghfhfhbr  阅读(166)  评论(0编辑  收藏  举报