sp_renamedb

Description

Changes the name of a user database.

Syntax

sp_renamedb dbname, newname

Parameters

dbname

is the original name of the database.

newname

is the new name of the database. Database names must conform to the rules for identifiers and must be unique.

Examples

Example 1

Renames the accounting database to financial:

sp_renamedb accounting, financial

Example 2

Renames the database named work, which is a Transact-SQL reserved word, to workdb. This example shows how sp_dboption is used to place the work database in single-user mode before renaming it and restore it to multi-user mode afterward:

sp_dboption work, single, true
go
use work 
go
checkpoint 
go
sp_renamedb work, workdb 
go
use master 
go
sp_dboption workdb, single, false 
go
use workdb 
go
checkpoint
go

Usage

Permissions

Only a System Administrator can execute sp_renamedb.

See also

Commands create database

System procedures sp_changedbowner, sp_dboption, sp_depends, sp_helpdb, sp_rename