Skip to content

Instantly share code, notes, and snippets.

@cdussud
Created January 18, 2021 19:54
Show Gist options
  • Save cdussud/36ee8f4b78d3578ffd494e5195b8ab21 to your computer and use it in GitHub Desktop.
Save cdussud/36ee8f4b78d3578ffd494e5195b8ab21 to your computer and use it in GitHub Desktop.
Generate a sequence of numbers in Azure SQL
-- 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;
@cdussud
Copy link
Author

cdussud commented Jan 18, 2021

This should work for any MS database using T-sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment