Generate SQL Server Test Data

I came across (thanks Paul) a great way to quickly generate test data for SQL Server today.

DECLARE @rows INT, @a int

 SET @rows = 50

 SELECT * INTO dbo.RobTest FROM

(SELECT TOP (@rows)

Rownumber = ROW_NUMBER() OVER (ORDER BY (SELECT 1)),

 SomeInt = ABS(CHECKSUM(NEWID())) % 50000 + 1 ,

 SomeLetters2 = CHAR(ABS(CHECKSUM(NEWID())) % 26 + 65) + CHAR(ABS(CHECKSUM(NEWID())) % 26 + 65) ,

 SomeMoney = CAST(ABS(CHECKSUM(NEWID())) % 10000 / 100.0 AS MONEY) ,

 SomeDate = CAST(RAND(CHECKSUM(NEWID())) * 3653.0 + 36524.0 AS DATETIME) ,

 SomeHex12 = RIGHT(NEWID(), 12),

 TrueRandomZerotoOne = RAND(CHECKSUM(NEWID()))

 FROM sys.all_columns ac1 CROSS JOIN sys.all_columns ac2 CROSS JOIN sys.all_columns ac3

 ) AS a

Print | posted on Tuesday, October 11, 2011 11:50 AM

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Comment:
Verification: