Skip to content

Instantly share code, notes, and snippets.

@Fasteroid
Last active February 7, 2025 17:40
Show Gist options
  • Select an option

  • Save Fasteroid/64d045ea784172528a7af5dbabd0bf06 to your computer and use it in GitHub Desktop.

Select an option

Save Fasteroid/64d045ea784172528a7af5dbabd0bf06 to your computer and use it in GitHub Desktop.
Generates ridiculous numbers of rows in Microsoft SQL Server
-- This query generates a list of as many numbers as you want, for Microsoft SQL Server.
DECLARE @Quantity INT = 100000; -- how many to generate
DECLARE @Growth INT = 10; -- exponential growth rate
WITH base AS (
SELECT number
FROM master..spt_values
WHERE type = 'P'
AND number < @Growth
),
cte_exponential(lvl)
AS (
SELECT
0
FROM
base
UNION ALL
SELECT
x.lvl + 1
FROM
cte_exponential x
CROSS JOIN (
SELECT
null AS _
FROM
base
) AS y
WHERE
x.lvl < LOG(@Quantity, @Growth) - 1
)
SELECT TOP (@Quantity) ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) - 1
FROM cte_exponential
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment