SQLServer更新一组随机数

--创建用于生成随机数的视图
create view view_rand
as
select cast(rand()*20 as int) as rd
go

--创建生成随机数的标量函数
create function getRand()
returns int
as
begin
return (select rd from view_rand)
end
go

--测试
--select dbo.getRand()

--更新随机0-19的随机值
update [QPAccountsDB].[dbo].[AccountsInfo] set FaceID=dbo.getRand() where IsAndroid=1


select * from [QPAccountsDB].[dbo].[AccountsInfo] where IsAndroid=1

drop view view_rand
drop function getRand

posted @ 2015-12-22 17:02  唔愛吃蘋果  阅读(867)  评论(0编辑  收藏  举报