快速生成100W条数据

 快速生成100W条数据,生成的时候是顺序生成,取的时候是随机取用,生成100W条数据大概一分多钟,比网上其他代码速度要快很多

CREATE TABLE tb(id char(6))

--truncate table tb
--select top 1 id from tb order by NEWID()
--select ID from tb where id ='190300'

select COUNT(1) from tb

SET NOCOUNT ON;

declare @i int = 0
while @i<10000
begin
insert into tb(id) values( cast(RIGHT(100000000 + CONVERT(bigint, @i), 6) as varchar(6)))
set @i=@i+1
end

declare @n int =0
while @n<9
begin
set @n=@n+1
insert into tb
select '0'+CAST(@n as char(1))+SUBSTRING(ID,3,4) from tb where ID<'010000'
waitfor delay '00:00:01'
end


declare @m int =0
while @m<9
begin
set @m=@m+1
insert into tb
select CAST(@m as char(1))+SUBSTRING(ID,2,5) from tb where ID<'100000'
waitfor delay '00:00:01'
end

select COUNT(1) from tb

 

posted @ 2018-08-22 18:29  davidhou  阅读(751)  评论(0编辑  收藏  举报