tags:

views:

36

answers:

2

I would like to write the SQL (MS SQL 2005/08) script to insert random large number of data in the database to test the system again heavy data.

Now consider that i have sample of data like below for some columns

stats [fail, pending, success, done, successful, partial_done]
date [range preferably two end dates]

Now can i write SQL script which can pick the random entry for these columns from range and can help me create realistic random data instead of repeating only single entry ?

+2  A: 

If you store the sample data in a table:

INSERT INTO table (COL1, COL2, COL3) VALUES
(SELECT COL1 from sample order by RAND() LIMIT 1),
(SELECT COL2 from sample order by RAND() LIMIT 1),
(SELECT COL3 from sample order by RAND() LIMIT 1)
Konerak
wow this looks great... thanks
Anil Namde
This seems to be MySQL syntax not SQL Server. There is no 'LIMIT' in SQL Server, subqueries aren't allowed in the `VALUES` clause and 'RAND()' evaluates as a constant value for all rows.
Martin Smith
+1  A: 

The accepted answer for this question looks somewhat inappropriate.

Assuming the assumption about sample data is correct then a way that will insert more than 1 row at a time and actually work in SQL Server is as follows.

INSERT INTO table (COL1, COL2, COL3) 
  SELECT TOP 1000 s1.COL1, s2.COL2, s3.COL3
  FROM sample s1, sample s2, sample s3
   ORDER BY NEWID()
Martin Smith
Thank you for your attentiveness - I indeed replied with MySQL. This answer should be the accepted answer.
Konerak