得到1-2亿的随机数select rand()*200000000

解决方案 »

  1.   

    如果要取整select convert(bigint,rand()*200000000)由于2亿超过int值的上限,需要用bigint型
      

  2.   

    插入方法
    (假设原来的table有一个identity(1,1)列id,如果没有可以
    alter table table1 add id bigint identity(1,1))新建一临时表create table #tmp(id bigint identity(1,1),randnum bigint)declare @a bigint
    set @a=0while @a<200000000
    begin
      insert into #tmp(randnum) select convert(bigint,rand()*200000000)
      set @a=@a+1
    end然后根据临时表的randnum列来更新table1的sj列update table1 set sj=randnum
    from #tmp  where table1.id=#tmp.id由于数据量大,可能需要比较长的时间,而且生成的日志也会比较大,要预留足够的磁盘空间和临时DB