Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favourite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved in your SSC briefcase from the favorites tab.
Download now (direct download link)

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

By Cade Bryant,

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.

Total article views: 1660 | Views in the last 30 days: 8
 
Related Articles
FORUM

sql script to find which user started restore and stopped while database was restoring in sql server 2008.

sql script to find which user started restore and stopped while database was restoring in sql server...

FORUM

Database Restoration

Unnecessary database restoration

FORUM

sql script to find which user started restore and stopped while database was restoring in sql server 2008

sql script to find which user started restore and stopped while database was restoring in sql server...

SCRIPT

Script to Get the Database Restore history

Script to get the Database restore history details including with the files by which the database is...

Tags
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones