SQL循环+游标

/****** Script for SelectTopNRows command from SSMS  ******/
use DB
  declare @id bigint
  DECLARE cur CURSOR
FOR ( select id from ptable where src is null)
OPEN cur;
  FETCH NEXT FROM cur INTO @id;

WHILE @@FETCH_STATUS = 0
    BEGIN
       print @id
         update ptable set src=(select top 1 nick from [user] order by newid()) where id=@id
        FETCH NEXT FROM cur INTO @id;
    END
CLOSE cur; --关闭游标
DEALLOCATE cur; --释放游标
GO

上一篇:跟着PHP100第一季学写一个CMS(1-10)


下一篇:tomcat启动(三)Catalina分析-load方法分析