while @i<100001 begin set @name='name_'+convert(varhar(20),@i) insert 表 values(@i,@name,20) set @i=@i+1 end
用笛卡尔积(连接)比较最高效 比如,下面的语句插入了4*4 = 16条记录,如果要插入100000=10*10*10*10*10,改成5个表,每个虚表UNION 10条记录,另外针对你的表结构稍微修改就OK,明白没有; create table tb ( x varchar(10)) insert tb select a.x + b.y from (select x='a' union select 'b' union select 'c' union select 'd' ) a , (select y='e' union select 'f' union select 'g' union select 'h' ) b
declare @name varchar(20)
set @i=1
while @i<100001
begin
set @name='name_'+convert(varhar(20),@i)
insert 表 values(@i,@name,20)
set @i=@i+1
end
比如,下面的语句插入了4*4 = 16条记录,如果要插入100000=10*10*10*10*10,改成5个表,每个虚表UNION 10条记录,另外针对你的表结构稍微修改就OK,明白没有;
create table tb ( x varchar(10))
insert tb
select a.x + b.y
from
(select x='a' union
select 'b' union
select 'c' union
select 'd' ) a ,
(select y='e' union
select 'f' union
select 'g' union
select 'h' ) b