sp_renamedb (T-SQL)

Changes the name of a database.

Syntax

sp_renamedb [@old_name =] 'old_name',
    [@new_name =] 'new_name'

Arguments
[@old_name =] 'old_name'
Is the current name of the database. old_name is sysname, with no default.
[@new_name =] 'new_name'
Is the new name of the database. new_name must follow the rules for identifiers. new_name is sysname, with no default.
Return Code Values

0 (success) or a nonzero number (failure)

Result Sets

None

Remarks

Before a database is renamed, it must be put into single-user mode by using sp_dpoption, and then restored to multiuser mode afterward.

Permissions

Only members of the sysadmin fixed server role can execute sp_renamedb.

Examples

This example changes the name of the accounting database to financial.

EXEC sp_renamedb 'accounting', 'financial'

  

See Also
CREATE DATABASE sp_helpdb
sp_changedbowner sp_rename
sp_dboption System Stored Procedures
sp_depends  

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.