update 表 set region_id=convert(numeric,rand()*10000000 )
--产生随机7位的整数: select right('000000' + cast(cast(rand()*10000000 as int) as varchar),7)
每一行的该列都是随机的。eg2: 生成随机考勤打卡资料:declare @r int --得到要处理的记录数 set @r=900--创建得到随机时间的临时表 create table #tb(id int identity(1,1),dt1 datetime,dt2 datetime,dt3 datetime,dt4 datetime,dt5 datetime,dt6 datetime)--生成随机时间 declare @sql varchar(8000) set @sql='insert into #tb(dt1,dt2,dt3,dt4,dt5,dt6) select top '+cast(@r as varchar)+' dateadd(ss,rand(a.id)*1800,''07:30''), dateadd(ss,rand(a.id+1)*400,''11:30''), dateadd(ss,rand(a.id+2)*1600,''13:00''), dateadd(ss,rand(a.id+3)*300,''17:30''), dateadd(ss,rand(a.id+4)*800,''17:45''), dateadd(ss,rand(a.id+5)*250,''20:00'') from(select top 100 id from sysobjects) a, (select top 9 id from sysobjects) b order by newid() exec(@sql) 当然,如果将07:30 11:30 ...这些时间改成排班时间就更好了。
建议如下: alter table 表名 add iid int identity(1,1) update 表名 set region_id = rand(id*8000)*1000 alter table 表名 drop column iid
select right('000000' + cast(cast(rand()*10000000 as int) as varchar),7)
--得到要处理的记录数
set @r=900--创建得到随机时间的临时表
create table #tb(id int identity(1,1),dt1 datetime,dt2 datetime,dt3 datetime,dt4 datetime,dt5 datetime,dt6 datetime)--生成随机时间
declare @sql varchar(8000)
set @sql='insert into #tb(dt1,dt2,dt3,dt4,dt5,dt6) select top '+cast(@r as varchar)+'
dateadd(ss,rand(a.id)*1800,''07:30''),
dateadd(ss,rand(a.id+1)*400,''11:30''),
dateadd(ss,rand(a.id+2)*1600,''13:00''),
dateadd(ss,rand(a.id+3)*300,''17:30''),
dateadd(ss,rand(a.id+4)*800,''17:45''),
dateadd(ss,rand(a.id+5)*250,''20:00'')
from(select top 100 id from sysobjects) a,
(select top 9 id from sysobjects) b
order by newid()
exec(@sql)
当然,如果将07:30 11:30 ...这些时间改成排班时间就更好了。
alter table 表名 add iid int identity(1,1)
update 表名 set region_id = rand(id*8000)*1000
alter table 表名 drop column iid