| title | sp_renamedb (Transact-SQL) | Microsoft Docs | ||
|---|---|---|---|
| ms.custom | |||
| ms.date | 03/14/2017 | ||
| ms.prod | sql | ||
| ms.prod_service | database-engine | ||
| ms.reviewer | |||
| ms.technology | system-objects | ||
| ms.topic | language-reference | ||
| f1_keywords |
|
||
| dev_langs |
|
||
| helpviewer_keywords |
|
||
| ms.assetid | 7dd9d4ff-20e1-4857-9a8e-a5bff767cf76 | ||
| author | stevestein | ||
| ms.author | sstein |
[!INCLUDEtsql-appliesto-ss2008-asdbmi-xxxx-xxx-md]
Changes the name of a database.
Important
[!INCLUDEssNoteDepFutureAvoid] Use ALTER DATABASE MODIFY NAME instead. For more information, see ALTER DATABASE (Transact-SQL).
Transact-SQL Syntax Conventions
sp_renamedb [ @dbname = ] 'old_name' , [ @newname = ] 'new_name'
[ @dbname = ] 'old_name'
Is the current name of the database. old_name is sysname, with no default.
[ @newname = ] 'new_name'
Is the new name of the database. new_name must follow the rules for identifiers. new_name is sysname, with no default.
0 (success) or a nonzero number (failure)
Requires membership in the sysadmin or dbcreator fixed server roles.
The following example creates the Accounting database and then changes the name of the database to Financial. The sys.databases catalog view is then queried to verify the new name of the database.
USE master;
GO
CREATE DATABASE Accounting;
GO
EXEC sp_renamedb N'Accounting', N'Financial';
GO
SELECT name, database_id, modified_date
FROM sys.databases
WHERE name = N'Financial';
GO
Database Engine Stored Procedures (Transact-SQL)
ALTER DATABASE (Transact-SQL)
sp_changedbowner (Transact-SQL)
sp_helpdb (Transact-SQL)
sys.databases (Transact-SQL)
System Stored Procedures (Transact-SQL)