可复制代码直接使用。(注:请先备份数据再进行测试!)
declare @max integer,@id integer
declare cur_rows cursor local for
select Employee_No,count(*) from Employee group by Employee_No 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 Employee where Employee_No = @id
fetch cur_rows into @id,@max
end
close cur_rows
set rowcount 0