The Basics of Using GENERATE_SERIES()


First, SQL Server 2022 has many interesting new features for both DBAs and database developers. GENERATE_SERIES is one of the new additions, and will likely please a lot of database developers and administrators. This function allows us to create a table of rows. Essentially, this function generates a list of sequential numbers as rows.

At first glance this appears to be exactly like the IDENTITY attribute and SEQUENCE object. IDENTITY and SEQUENCE generate numbers only we INSERT rows or call NEXT VALUE FOR.  The GENERATE_SERIES() function is different. Every time GENERATE_SERIES is executed it generates the series of numbers. GENERATE_SERIES