Last active
February 7, 2025 17:40
-
-
Save Fasteroid/64d045ea784172528a7af5dbabd0bf06 to your computer and use it in GitHub Desktop.
Generates ridiculous numbers of rows in Microsoft SQL Server
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
| -- 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