Generate Large Amount of Data For Performance Testing

,

While taking my training classes for SQL Server, students ask many times if they can get some large sample tables to do perfroamce tuning. So I thought of writing a script to generate the sample data as per my need. To use this script to generate data, you need to have AdventureWorks2012 DB on that machine. If you don't have it, you may download it from :

https://github.com/Microsoft/sql-server-samples/releases/tag/adventureworks

Then you may run the script to generate sample data in table AllCustomerOrders. You just need to specify how many rows you want to generate. e.g. to generate 100 records, I have specified it like this:

Declare @RowsRequired Bigint =100

So instead of 100, you may specify a big number.

I tried a sample run on my Core i5 4 GB RAM laptop And below are the results:
Number Of records Size TimeTaken(hh:mm:ss)
5 million - 500MB 00:04:00
10 million 990 MB 00:09:00
90 million     8.9 GB 01:49:00
If any of you need explanation how the code is written, Let me know and I will be happy to assist.

CREATE TABLE AllCustomerOrders(OrderID BigInt Primary Key,
CustomerID BigInt,
FirstName Varchar(100),
LastName Varchar(100),
ProductID Bigint,
UnitPrice Decimal(10,2),
OrderAmount Decimal(10,2),
OrderDate Datetime,
ShipDate Datetime)
GO

--INSERT RECORDS NOW
Declare @RowsRequired Bigint =100

;With CTE AS (
			Select Row_Number() Over (Order BY A.BusinessEntityID) CustomerID ,
				   A.FirstName ,
				   B.LastName 
			FROM person.person A CROSS JOIN person.person B)
INSERT INTO AllCustomerOrders(OrderID,CustomerID,FirstName,LastName,ProductID,UnitPrice,OrderAmount,OrderDate,ShipDate )
SELECT distinct OrderID,X.CustomerID,FirstName,LastName,ProductID,UnitPrice,OrderAmount,OrderDate,ShipDate 
FROM (SELECT Row_Number() Over (Order BY cAST(A.CustomerID AS BIGINT)) OrderID,A.*,SalesOrderID,ProductID,B.UnitPrice,LineTotal OrderAmount 
FROM CTE A CROSS JOIN   sales.salesOrderDetail B ) X
JOIN [Sales].[SalesOrderHeader] C ON C.SalesOrderID =X.SalesOrderID
WHERE OrderID<=@RowsRequired

Rate

2.67 (3)

Share

Share

Rate

2.67 (3)