What is the quickest way to fill a SQL table with dummy data?
I have a wide table with about 40 fields of different kinds (int, bit, varchar, etc.) and need to do some performance testing. I'm using SQL Server 2008.
To use it, navigate to the link and insert a SQL command that defines the tables or use their dummy tables. Then click next and fill out your rows data types and settings for dummy data population. Then click next and generate the data.
To create a random integer number between two values (range), you can use the following formula: SELECT FLOOR(RAND()*(b-a+1))+a; Where a is the smallest number and b is the largest number that you want to generate a random number for.
You Only need Go 1000
after your INSERT, to fill it 1000 times, just like this:
INSERT INTO dbo.Cusomers(Id, FirstName, LastName) VALUES(1, 'Mohamed', 'Mousavi') GO 1000
It will make a table with 1000 same rows in it.
Another solution is that you can populate the beginning rows of your table with some data, then you fill the next rows of table by repeating the beginning rows over and over, it means you fill your table by itself:
INSERT INTO dbo.Customers SELECT * FROM dbo.Customers GO 10
In the case one or more column are identity (meaning they accept unique values, if it's auto incremental), you just don't place it in your query, for instance if Id in dbo.Customer is identity, the query goes like this:
INSERT INTO dbo.Customers SELECT FirstName, Last Name FROM dbo.Customers GO 10
Instead Of:
INSERT INTO dbo.Customers SELECT Id, FirstName, Last Name FROM dbo.Customers GO 10
Else you'll encounter this Error:
An explicit value for the identity column in table 'dbo.Customers' can only be specified when a column list is used and IDENTITY_INSERT is ON.
Note: This is sort of an arithmetic progression, so it's going to last a little, don't use a big number in front of GO
.
If you want to have a table which is filled a little bit more elaborated then you can achieve that the same way this time by executing a simple query and following these steps:
Choose one of your tables which has a remarkable number of rows, say dbo.Customers
Right click on it and select Script Table as > Create To > New Query Editor Window
Name your new table to something else like dbo.CustomersTest, Now you can execute the query to have a new table with similar structure with the dbo.Customers.
Note:Keep in mind that if it has a Identity filed, change it's Identity Specification to No
Since you are supposed to fill the new table by the data of the original one repeatedly.
INSERT INTO [dbo].[CustomersTest] SELECT * FROM [dbo].[Customers] GO 1000
As @SQLMenace mentioned, RedGate Data Generator is a so good tool to fulfill it, it costs $369, you have a 14 days trial chance Although.
The good point is that RedGate identifies foreign keys so you can apply JOIN in your queries.
You have a bunch of options which allow you to decide how every column is supposed to be populated, every column is anticipated semantically so that related data are suggested, for instance if you have a column named 'Department' it isn't filled by weird characters, it's filled by expressions like "Technical", "Web", "Customer", etc. Even you can use regular expression to restrict selected characters.
I populated my tables with over 10,000,000 records which was an awesome simulation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With