Sql游标
DECLARE @ID varchar( 50 ) declare @resourceID varchar( 50 ) DECLARE My_Cursor CURSOR --定义游标 FOR (SELECT ID,resourceID FROM dbo.Resource_Main) --查出需要的集合放到游标中 OPEN My_Cursor; --打开游标 FETCH NEXT FROM My_Cursor INTO @ID,@resourceID; WHILE @@FETCH_STATUS = 0 BEGIN print @ID; update Resource_Attach_Link set ResourceID=@resourceID where ResourceID=@ID FETCH NEXT FROM My_Cursor INTO @ID,@resourceID; --读取下一行数据(将MemberAccount表中的UserId放到@UserId变量中) END CLOSE My_Cursor; --关闭游标 DEALLOCATE My_Cursor; --释放游标 GO 来源: https://www.cnblogs.com/theMaxBear/p/5553838.html