SQL游标使用步聚

当你需要对select出来的结果循环处理的时候就需要用到游标。
如下面的一个存储过程中就用了一个游标:
Create Proc Pr_DeleteTable 
as 
declare @Table varchar(20) 
declare cr_cursor cursor --1.定义游标 
for select name from dbo.sysobjects where xtype='U' and status>0 
open cr_cursor --2.打开游标 
fetch From cr_cursor into @Table --3.提取游标 
while @@fetch_status=0 
begin 
print @Table --执行打印操作 
fetch next From cr_cursor into @Table 
end; 
close cr_cursor --4.关闭游标 
deallocate cr_cursor --5.释放游标 
原文地址:https://www.cnblogs.com/mokliu/p/2138855.html