Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server slow down after duplicating database

I recently moved a bunch of tables from an existing database into a new database due to the database getting rather large. After doing so I noticed a dramatic decrease in performance of my queries when running against the new database.

The process I took to recreate the new database is this:

  1. Generate Table CREATE scripts using sql servers automatic script
    generator.
  2. Run the create table scripts
  3. Insert all data into new database using INSERT INTO with a select from the existing database.
  4. Run all the alter scripts to create the foreign keys and any indexes

Does anyone have any ideas of possible problems with my process, or some key step I'm missing that is causing this performance issue?

Thanks.

like image 377
cweston Avatar asked Dec 21 '25 02:12

cweston


2 Answers

first I would an a mimimum make sure that auto create statistics is enabled you can also set auto update statistics to true

after that I would update the stats by running

sp_updatestats

or

UPDATE STATISTICS

Also realize that the first time you hit the queries it will be slower because nothing will be cached in RAM. On the second hit should be much faster

like image 176
SQLMenace Avatar answered Dec 22 '25 18:12

SQLMenace


Did you script the indexes from the tables in the original database? Missing indexes could certainly account for poor performance.

like image 33
George Mastros Avatar answered Dec 22 '25 18:12

George Mastros



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!