Skip to content

Instantly share code, notes, and snippets.

@EHLOVader
Last active December 23, 2015 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EHLOVader/6555301 to your computer and use it in GitHub Desktop.
Save EHLOVader/6555301 to your computer and use it in GitHub Desktop.
Create a test table filled with 1000 numbers Based off single insert code sample #7 from SO http://stackoverflow.com/questions/1393951/what-is-the-best-way-to-create-and-populate-a-numbers-table Updated for MSSQL with conditional drop table to avoid errors Updated to use zero-based numbering, because it is better http://c2.com/cgi/wiki?WhyNumber…
/**
* NumbersTest
* Create a test table filled with 1000 numbers
*
* Based off single insert code sample #7 from the below SO
* @see http://stackoverflow.com/questions/1393951/what-is-the-best-way-to-create-and-populate-a-numbers-table
*
* Updated for MSSQL with conditional drop table to avoid errors
*/
IF OBJECT_ID('dbo.NumbersTest', 'U') IS NOT NULL
DROP TABLE NumbersTest
DECLARE @RunDate datetime
SET @RunDate=GETDATE()
SELECT TOP 10000 IDENTITY(int,0,1) AS Number
INTO NumbersTest
FROM sys.objects s1
CROSS JOIN sys.objects s2
ALTER TABLE NumbersTest ADD CONSTRAINT PK_NumbersTest PRIMARY KEY CLUSTERED (Number)
PRINT CONVERT(varchar(20),datediff(ms,@RunDate,GETDATE()))+' milliseconds'
SELECT COUNT(*) FROM NumbersTest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment