34,590
社区成员
发帖
与我相关
我的任务
分享
drop table t
go
create table t(num int )
go
insert into t(num)
select top 6000 row_number() over (order by a.id)
from sysobjects a, sysobjects b
go
select * from t
go
(6000 行受影响)
num
-----------
1
2
3
4
....
5997
5998
5999
6000
(6000 行受影响)
create table Acc_num(num int)
go
;with cte as(
select 1 as id
union all
select id+1 as id from cte where id<60000
)
INSERT INTO Acc_Num select id from cte OPTION (MAXRECURSION 0);
go
select * from Acc_num order by num
/*
......
59994
59995
59996
59997
59998
59999
60000
(60000 行受影响)
*/
go
drop table Acc_num
DECLARE @maxNum int
INSERT INTO Acc_Num VALUES(1)
SET @maxNum = 1
WHILE @maxNum < 60000
BEGIN
INSERT INTO Acc_Num
SELECT @maxNum + num
FROM Acc_Num
WHERE @maxNum + num <= 60000
SET @maxNum = @maxNum*2
END
if exists(select 1 from sys.objects where type='U' and name='Acc_Num') drop table Acc_Num
go
select top 60000 num=identity(int,1,1)into Acc_Num from syscolumns a,syscolumns b
go
select * from acc_num