/****** 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