# 简单而又复杂的问题

gzhotsale2002 2004-04-29 10:08:23

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

...全文
15 3 点赞 打赏 收藏 举报

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
• 打赏
• 举报

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
• 打赏
• 举报

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

• 打赏
• 举报

3.3w+

MS-SQL Server相关内容讨论专区

2004-04-29 10:08