SQL Server DBA Tips Corner

     Return to the SQL Server DBA Tips Corner.

click me  


Renaming a Database

by Jeff Hunter, Sr. Database Administrator


Contents

  1. Overview
  2. Restrictions



Overview

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'



Restrictions

Example

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


Copyright (c) 1998-2010 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
Monday, 25-Jul-2005 19:25:13 EDT
Page Count: 14207