sql server 游标语法

DECLARE @ID int

--定义游标

DECLARE MyCursor CURSOR

FOR SELECT ID FROM tbclass_1

--打开一个游标

OPEN MyCursor

--循环一个游标

FETCH NEXT FROM MyCursor INTO @ID

WHILE @@FETCH_STATUS =0

BEGIN

--sql代码块

FETCH NEXT FROM  MyCursor INTO @ID

END

CLOSE MyCursor --关闭游标

DEALLOCATE MyCursor --释放游标

原文地址:https://www.cnblogs.com/suger/p/2193039.html