SQL Script To Rename An Existing SQL Server Database

 

Use this SQL server script from the SQL query window to rename an existing database. The script below will place the database in single user mode then rename the device and put then new device name back into multi user mode for use.

 

SQL Script:

 

Use Master

Go

 

Sp_DbOption <Current_Database>, 'Single User', True

Go

 

Exec Sp_ReNameDb '<Current_Database_Name>', '<New_Database_Name>'

Go

 

Sp_DbOption <New_Database_Name>, 'Single User', False

Go

 

Note: You must restart or refresh the Query Analyzer to view the name change

 

 

Published Sunday, December 30, 2007 1:55 PM by dhite
Filed under:

Comments

# SQL Script To Rename An Existing SQL Server Database

Use this SQL server script from the SQL query window to rename an existing database. The script below will place the database in single user mode then rename the device and put then new device name ba ...

Monday, December 31, 2007 11:04 AM by Ramblings, Scriptlets, and more!