SQLServer更新数据库每行一个随机数
代码:
DECLARE @user_id varchar(36) DECLARE user_extension_cursor CURSOR FOR SELECT UserCode FROM Users OPEN user_extension_cursor; FETCH NEXT FROM user_extension_cursor INTO @user_id WHILE @@FETCH_STATUS = 0 BEGIN UPDATE Users set UserLevel=cast(ceiling(rand() * 5) as int) WHERE UserCode = @user_id FETCH NEXT FROM user_extension_cursor INTO @user_id END CLOSE user_extension_cursor; DEALLOCATE user_extension_cursor;