插入100000条记录,值为1 2 3 ...... 100000

我真的不知道该这么办了。

declare @i int
set @i=0
while @i<=100000
begin
if exists (select f1 from t1 where f1=@i)
begin
raise error('重复了',15,2)
return
end
insert into t1(f1,f2) (@i,@i*2)
set @i=@i+1
end
类试这样的一段代码,要在数据库中插入记录,运行了30分钟。
大侠请出手,帮我想想办法吧。
---------------------------------------------------------------

select n = identity(int,1,1)
into #a
from (select top 100 a=1 from syscolumns) as a,
(select top 100 a=1 from syscolumns) as b,
(select top 10 a=1 from syscolumns) as c

insert into t1(f1,f2)
select n,n*2 from #a
where n not in(select f1 from t1)

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus