导航

sql server 删除表中的重复记录

Posted on 2011-08-03 09:19  yjss  阅读(132)  评论(0编辑  收藏  举报
declare @max integer,@id integer
declare cur_rows cursor local for 
select id,count(*) from 表名 group by id 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 表名 where id = @id
fetch cur_rows into @id,@max
end
close cur_rows
set rowcount 0