How to generate numbers table in SQL?
1. Generate Number table with cross join and row_number function
In this method, we are squaring the number of records from the previous CTE and generate a new CTE. In this way, we are able to generate a table with 4^32 records. Then we are using the ROW_NUMBER function to generate the numbers and limit the numbers based on the maximum number that we want to generate. This solution is originally created by Itzik Ben-Gan
2. Use generate_series() built-in function
This function is relatively new and it is available in SQL Server 2022 preview version.
I suggest you to read Erland Sommarskog’s article on table of numbers for other interesting solutions.