Some time ago, I found this handy T-SQL script on the Web, which creates a table with a million rows (1, 2, 3, ... 999999, 1000000):
-- Declare a variable to hold the
-- count of rows to be generated
Declare @p_NumberOfRows Bigint
-- We need 1 million rows
Select @p_NumberOfRows=1000000;
With Base As
(
Select 1 as n
Union All
Select n+1 From Base Where n < Ceiling(SQRT(@p_NumberOfRows))
),
Expand As
(
Select 1 as C
From Base as B1, Base as B2
),
Nums As
(
Select Row_Number() OVER(ORDER BY C) As n
From Expand
)
Select n into BigTable from Nums Where n<=@p_NumberOfRows
-- Remove Maximum Recursion level constraint
OPTION (MaxRecursion 0);
It runs great with Microsoft SQL Server 2005.
No comments:
Post a Comment