Search
Monday, March 27, 2017 ..:: Home ::.. Register  Login
   Calendar  
     
  
   Search  
     
  
   Blogroll  
     
  
   Disclosure  
All blog entries are the opinions of the author and do not necessarily reflect the opinions of their employer. All the code presented is for explanation and demonstration purposes only. Any damages incurred to your site and/or data are not the responsibility of the author. Every effort is taken to ensure the code properly compiles, however sometimes there are some hiccups and you might be required to do your own debugging.
     
  
   TechTidBits (Blog)  

Adding MASSIVE testing data to your Database?

Mar 1

Written by:
Tuesday, March 01, 2016 9:50 PM  RssIcon

imageToday I needed to add 250,000 users, what’s the fastest way to do this?

Today, I need to add a BOAT load of data to my db, 250,000 users. Yup, THAT many. Our VP wanted us to test our webpage with “a lot of users” and threw out 240,000. So why not try it out! Well, what’s the quickest way to get that many users into the db? I’m sure there are a few C# ways, PowerShell, but I had SQL Server opened and figured there HAD to be a looping way in sql. Yup!

declare @maxVal int = 250000;

declare @currVal int = 0;

while( @currVal < @maxVal)

begin

     insert into EventLog values (newid(), 10, getdate(), 2010, 'Habs\Carey.Price' + cast(@currVal as varchar),

         'Habs1996', NULL, N'true', getdate(), NULL, NULL, '2016-01-12')

     set @currVal = @currVal + 1;

end select * from EventLog el where el.[user] like 'habs\carey.price%'

The deal here is, setup your upper max val, your loop invariant, do a while over those two vals. Next I’m doing a standard SQL insert but since I want names to be different, I’m tacking on the loop counter to the end, but don’t forget to cast it to a varchar otherwise you’ll get an error. Next, don’t forget to increase your loop invariant, otherwise you’ll be in an infinite loop. And then lastly, I try to see just the new data I added.

Now that you know one of MANY ways to quickly whip out testing data, it’s time to grab a coffee and get coding!

Tags:
Categories:
Location: Blogs Parent Separator TechTidBits

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Add Comment   Cancel 
     
  
Copyright 1999-2012 by PCHenry.com   Terms Of Use  Privacy Statement