Created
January 18, 2021 19:54
-
-
Save cdussud/36ee8f4b78d3578ffd494e5195b8ab21 to your computer and use it in GitHub Desktop.
Generate a sequence of numbers in Azure SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 10M numbers for Azure SQL Database | |
WITH digit (d) AS | |
( | |
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 | |
), | |
seq (num) as ( | |
select top 1000000000000 -- top is needed for order by | |
a.d + (10 * b.d) + (100 * c.d) + (1000 * d.d) + (10000 * e.d) + (100000 * f.d) + (1000000 * g.d) as num | |
from digit a | |
cross join | |
digit b | |
cross join | |
digit c | |
cross join | |
digit d | |
cross join | |
digit e | |
cross join | |
digit f | |
cross join | |
digit g | |
order by 1 | |
) | |
INSERT INTO demo.numbers | |
select num | |
from seq; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should work for any MS database using T-sql