遍历某个指定的表
1.使用游标
Use Master
Declare My_cursor cursor for
select name,number
from dbo.spt_values
where number=1
declare @sname varchar(50)
declare @snumber varchar(50)
open My_cursor
fetch next from My_cursor into @sname,@snumber
while(@@fetch_status = 0)
Begin
print @sname
print @snumber
fetch next from My_cursor into @sname,@snumber
End
close My_cursor
deallocate My_cursor