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

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

usp_ToggleDatabases

By David Rowland,

usp_ToggleDatabases is a simple procedure that will switch the names of two databases.

One of the main problems with using sp_renamedb to switch databases is that the procedure will wait until the database is free before the rename can be completed. If the new live database is also in use then there is a likelyhood that the renaming of the current database could be successful and the second database will fail.

The procedure attached will wait until all databases are free before trying to switch them around.

A total of 5 sets of databases can be passed to this procedure and it will not start switching any database unless all have noone accessing any of them at a given point.

Total article views: 476 | Views in the last 30 days: 4
 
Related Articles
FORUM

/3GB Switch

/3GB Switch

FORUM

Partition Table Switch Error

Cannot Switch Partition

FORUM

stored procedures in a database

stored procedures in a database

FORUM

Procedure to see database status

Procedure to see database status

FORUM

Problem with ALTER TABLE ... SWITCH

ALTER TABLE .... SWITCH doesnt work

 
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