Monday, March 19, 2018
Deceptively simple ... and potentially evil
drop table tNUM
CREATE TABLE dbo.tNUM
(
NUM INT PRIMARY KEY
);
WITH L0 AS (SELECT 1 AS c UNION ALL SELECT 1), -- 2
L1 AS (SELECT 1 AS c FROM L0 AS A CROSS JOIN L0 AS B), -- 4
L2 AS (SELECT 1 AS c FROM L1 AS A CROSS JOIN L1 AS B), -- 16
L3 AS (SELECT 1 AS c FROM L2 AS A CROSS JOIN L2 AS B), -- 256
L4 AS (SELECT 1 AS c FROM L3 AS A CROSS JOIN L3 AS B), -- 65,536
L5 AS (SELECT 1 AS c FROM L4 AS A CROSS JOIN L4 AS B), -- 4,294,967,296
L6 AS (SELECT 1 AS c FROM L5 AS A CROSS JOIN L5 AS B), -- 18,446,744,073,709,551,616
...
---- Nums AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS n FROM L2)
Nums AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS n FROM L5) --L6)
INSERT INTO dbo.tNUM ( NUM )
SELECT -- TOP (1000)
n
FROM Nums
--SELECT TOP (1000)
-- n
--FROM Nums
ORDER BY n;
SELECT COUNT (*) FROM tNum
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment