DBA Tips Archive for SQL Server


[an error occurred while processing this directive]

No Title

[an error occurred while processing this directive]

by Jeff Hunter, Sr. Database Administrator



Sometimes you might find it necessary to rename a database. This may come about due to a change in focus of the database or moving a database from development to production. The process is relatively straightforward.

The syntax for doing so uses the sp_renamedb system stored procedure:

1> EXEC sp_renamedb 'old_db_name', 'new_db_name'


The following restrictions exist for renaming a database:


The following example will rename the 'DevelopmentDB' database to 'ProductionDB':

USE master GO EXEC sp_dboption DevelopmentDB, 'Single User', True EXEC sp_renamedb 'DevelopmentDB', 'ProductionDB' EXEC sp_dboption ProductionDB, 'Single User', False

To verify that the database was actually renamed, run the following:

1> EXEC sp_helpdb name db_size owner dbid created ----------- --------- ------- ------- ----- master 11.94 MB sa 1 Aug 6 2000 model 1.13 MB sa 3 Aug 6 2000 msdb 13.00 MB sa 4 Aug 6 2000 Northwind 3.63 MB sa 6 Aug 6 2000 ProductionDB 2.00 MB sa 7 Nov 15 2001 pubs 2.00 MB sa 5 Aug 6 2000 tempdb 8.75 MB sa 2 Nov 15 2001

About the Author

Jeffrey Hunter is an Oracle Certified Professional, Java Development Certified Professional, Author, and an Oracle ACE. Jeff currently works as a Senior Database Administrator for The DBA Zone, Inc. located in Pittsburgh, Pennsylvania. His work includes advanced performance tuning, Java and PL/SQL programming, developing high availability solutions, capacity planning, database security, and physical / logical database design in a UNIX / Linux server environment. Jeff's other interests include mathematical encryption theory, tutoring advanced mathematics, programming language processors (compilers and interpreters) in Java and C, LDAP, writing web-based database administration tools, and of course Linux. He has been a Sr. Database Administrator and Software Engineer for over 20 years and maintains his own website site at: http://www.iDevelopment.info. Jeff graduated from Stanislaus State University in Turlock, California, with a Bachelor's degree in Computer Science and Mathematics.

Copyright (c) 1998-2018 Jeffrey M. Hunter. All rights reserved.

All articles, scripts and material located at the Internet address of http://www.idevelopment.info is the copyright of Jeffrey M. Hunter and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express, prior, written permission. Application to host any of the material elsewhere can be made by contacting me at jhunter@idevelopment.info.

I have made every effort and taken great care in making sure that the material included on my web site is technically accurate, but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.

Last modified on
Saturday, 18-Sep-2010 00:48:03 EDT
Page Count: 3063