Skip to content

Latest commit

 

History

History
75 lines (60 loc) · 2.9 KB

File metadata and controls

75 lines (60 loc) · 2.9 KB
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
sp_renamedb
sp_renamedb_TSQL
dev_langs
TSQL
helpviewer_keywords
sp_renamedb
ms.assetid 7dd9d4ff-20e1-4857-9a8e-a5bff767cf76
author stevestein
ms.author sstein

sp_renamedb (Transact-SQL)

[!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).

Topic link icon Transact-SQL Syntax Conventions

Syntax

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

Arguments

[ @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.

Return Code Values

0 (success) or a nonzero number (failure)

Permissions

Requires membership in the sysadmin or dbcreator fixed server roles.

Examples

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  

See Also

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)