If, like me, you are constantly restoring/moving several databases between multiple environments (development to staging, production to training, etc.), you know how tedious it can get to use EM, or to manually type out all those RESTORE...WITH MOVE statements in QA.
Even having a saved script isn't the ideal thing, as you still need to go in and change the database names and filenames for each restore; which often means having to run sp_helpdb for each database to get the MOVE TO path.
The following sproc provides a dynamic and automated way to restore specified databases (or all user databases), including the requisite MOVE statements. Enter a comma-delimited string of the databases you want to restore, or 'all' of you want to restore all user DBs.
Syntax: exec sp_RestoreDBS 'northwind,pubs'
OR: exec_sp_RestoreDBS 'all'
sp_Restore also has parameters for file paths, filenames, and suffixes, which you can set to your environment defaults.
Note: executing the sproc doesn't actually perform the restore; instead it generates the restore script which you can copy/paste into a new QA window and run. I did it this way because database restores are an extremely sensitive operation, and it's good to know exactly what code is being run against your databases.
I Need a Backup and I Need It Now
Have you ever wished that creating a backup on the fly was easier and quicker? Whether you do it with the GUI or with T-SQL, you still have to open up Management Studio, connect to the database, and go through the steps. You have to figure out ...
2009-04-29
4,263 reads