2014-03-19 32 views
0

在SQL Server 2008中使用遊標時,在哪個語句中將表中的值加載到遊標中?SQL Server 2008遊標何時加載表值?

declare @sname nvarchar(50) 

declare cur1 cursor 
for 
select sname from tstudent 


open cur1 
FETCH NEXT FROM cur1 INTO @sname 
print @sname 
WHILE @@FETCH_STATUS = 0 
    BEGIN 
     FETCH NEXT FROM cur1 INTO @sname 
     if @@FETCH_STATUS = 0 
      print @sname  
END 
CLOSE cur1 
DEALLOCATE cur 

回答

0

當你OPEN光標,光標會從DB使用DECLARE語句中指定的查詢填充。更多信息請登錄MSDN