DECLARE @user_id varchar(36)
DECLARE user_extension_cursor CURSOR
FOR
SELECT id
FROM [test].[dbo].[my_table]
OPEN user_extension_cursor;
FETCH NEXT FROM user_extension_cursor
INTO @user_id
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE [test].[dbo].[my_table]
SET [my_table].test_rand = cast(rand()*(999999-100000)+100000 as nvarchar(6))
WHERE id = @user_id
FETCH NEXT FROM user_extension_cursor INTO @user_id
END
CLOSE user_extension_cursor;
DEALLOCATE user_extension_cursor;
转自Ron Ngai