declare o_cursor cursor for select * from employee
declare @eid int,@cnt int
set @cnt = 0
open o_cursor
fetch next from o_cursor into @eid
while @@fetch_status = 0
begin
set @cnt = @cnt + 1
update employee set salary=salary+50 where eid=@eid
if ( @@error <> 0 ) rollback tran
if ( @cnt = 5 )
begin
commit
set @cnt=0
end
fetch next from o_cursor into @eid --这句一定要写,否则麻烦大了. :) 死循环
end
commit
close o_cursor
deallocate o_cursor