简单而又复杂的问题

gzhotsale2002 2004-04-29 10:07:09
请问 我要插入 10000条顺序的数字到 表 #tsequ 中,这种方法太慢了,除了这个方法,还有一些更快的方法吗 ?
谢谢

Create Table #tsequ (ti int)
declare @lni int
declare @lnj int

select @lni = 1
select @lnj = 10000

while @lni<=@lnj
Begin
insert #tsequ (ti) values (@lni)
select @lni = @lni + 1
End

...全文
28 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 2004-04-29
  • 打赏
  • 举报
回复
--或者:

Create Table #tsequ (ti int)

--直接插入10000万条
insert #tsequ
select id=a.id+b.id+c.id+d.id+1
from(
select id=0 union all select 1
union all select id=2 union all select 3
union all select id=4 union all select 5
union all select id=6 union all select 7
union all select id=8 union all select 9
) a,(
select id=0 union all select 10
union all select id=20 union all select 30
union all select id=40 union all select 50
union all select id=60 union all select 70
union all select id=80 union all select 90
) b,(
select id=0 union all select 100
union all select id=200 union all select 300
union all select id=400 union all select 500
union all select id=600 union all select 700
union all select id=800 union all select 900
) c,(
select id=0 union all select 1000
union all select id=2000 union all select 3000
union all select id=4000 union all select 5000
union all select id=6000 union all select 7000
union all select id=8000 union all select 9000
) d
order by id
8992026 2004-04-29
  • 打赏
  • 举报
回复
Create Table #tsequ (ti int)

insert #tsequ
select 1+a+10*b+100*c+1000*d
from (
select 0 as a
union all
select 1
union all
select 2
union all
select 3
union all
select 4
union all
select 5
union all
select 6
union all
select 7
union all
select 8
union all
select 9
) as a,(
select 0 as b
union all
select 1
union all
select 2
union all
select 3
union all
select 4
union all
select 5
union all
select 6
union all
select 7
union all
select 8
union all
select 9
) as b,(
select 0 as c
union all
select 1
union all
select 2
union all
select 3
union all
select 4
union all
select 5
union all
select 6
union all
select 7
union all
select 8
union all
select 9
) as c,(
select 0 as d
union all
select 1
union all
select 2
union all
select 3
union all
select 4
union all
select 5
union all
select 6
union all
select 7
union all
select 8
union all
select 9
) as d



zjcxc 2004-04-29
  • 打赏
  • 举报
回复

Create Table #tsequ (ti int)


select top 10000 id=identity(int,1,1) into #t from sysobjects a,syscolumns b

insert #tsequ select * from #t

drop table #t

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧