Last active
December 23, 2015 00:39
-
-
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…
This file contains 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
/** | |
* 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