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;
posted @ 2015-04-03 15:56  魏巍(QQ:68235081)  阅读(1264)  评论(0编辑  收藏  举报