一、
--双色球(六红一蓝) 红球1-33(不重复) 蓝球1-16
--七字段 Red1-6 Blue0--select * from shuangsq
--create table shuangsq(Red1 int,Red2 int,Red3 int,Red4 int,Red5 int,Red6 int,Blue0 int)
declare @r1 int,@r2 int,@r3 int,@r4 int,@r5 int,@r6 int,@b0 int
set @r1=1
while @r1<=28
begin
set @r2=@r1+1
while @r2<=29
begin
set @r3=@r2+1
while @r3<=30
begin
set @r4=@r3+1
while @r4<=31
begin
set @r5=@r4+1
while @r5<=32
begin
set @r6=@r5+1
while @r6<=33
begin
set @b0=1
while @b0<=16
begin
insert into shuangsq values(@r1,@r2,@r3,@r4,@r5,@r6,@b0)
set @b0=@b0+1
end
set @r6=@r6+1
end
set @r5=@r5+1
end
set @r4=@r4+1
end
set @r3=@r3+1
end
set @r2=@r2+1
end
set @r1=@r1+1
end
二、
create table tbl1(sid varchar(10))
bulk insert tbl1 from 'D:\456.txt 'with (fieldterminator=' ',rowterminator='\n')
select * from tbl1
--建游标
declare ur cursor for select * from tbl1 --游标是定义在以Select开始的数据集上的
open ur
declare @nb varchar(20),@sq varchar(200)
fetch from ur into @nb --循环前先fetch一下
while @@FETCH_STATUS=0 --游标读取下一条数据是否成功。
begin
set @sq='create table '+@nb+'(maths int,english int)'
exec (@sq)
fetch from ur into @nb
end
close ur
deallocate ur
select * from A0001
drop table A0006
三、
--职工号:用一个字母5个数字
--姓名:3个字母
--性别:0,1
--出生年月:>=20,<=60
--工资:5000-8000
--生成十万条记录,写出所用时间。完成后增加年龄字段,并求出每人的年龄
create table zhigong(zgid varchar(6),zgnm varchar(3),zggd varchar(1),zgbt date,zggz int)
declare @i int,@dd datetime,@zgh varchar(6),@xm varchar(3),@xb varchar(1),@cs date,@gz int,@nl int
set @i=0
set @dd=getdate()
while(@i<100)
begin
set @zgh=char(rand()*26+65)+cast(floor(rand()*90000+10000)as char)
set @xm=char(rand()*26+65)
set @xm=@xm+char(rand()*26+65)
set @xm=@xm+char(rand()*26+65)
set @xb=cast(floor(rand()*2)as char)
set @cs=dateadd(day,-(rand()*14600+7300),getdate())
set @gz=5000+rand()*3000
set @i=@i+1
insert into zhigong values(@zgh,@xm,@xb,@cs,@gz,@nl)
end
select datediff(ms,@dd,getdate())
--select *from zhigong
drop table zhigong
alter table zhigong add age int
update zhigong set age=datediff(year,zgbt,getdate())
select dateadd(day,-(rand()*14600+7300),getdate())
select rand()*14600+7300
select dateadd(day,-20912,getdate())