create table person
(
id int identity(1,1) not null,
pid varchar(18) not null,
md varchar(11) not null,
age int
)
go
declare @pid varchar(15)
declare @age int
declare @mb varchar(11)
declare @count int
set @count = 0
--插入100万条随机的记录
while(@count < 1000000)
begin
--生成随机的PID
select @pid=substring(cast(rand() as varchar(20)),3,6)+
substring(cast(rand() as varchar(20)),3,6)+substring(cast(rand() as varchar(20)),3,6)
--生成随机的MB
select @mb=substring(cast(rand() as varchar(20)),3,6)+
substring(cast(rand() as varchar(20)),3,5)
--生成随机的AGE
select @age = cast (rand() * 100 as int)
--将生成的随机数据插入表
insert into person
values ( @pid, @mb,@age)
set @count = @count + 1
end