SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

"RESTORE..... WITH MOVE" all databases on a server

By Cade Bryant, 2003/02/10

Total article views: 406 | Views in the last 30 days: 14

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.

By Cade Bryant, 2003/02/10

Total article views: 406 | Views in the last 30 days: 14
Your response
 
 
Related tags
 
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com