Rename Database Using Stored Procedure in SQL Server 2008

Change database name using stored procedure
  • 2627

Change database name using stored procedure

We can rename the database using sql query. Syntax for changing name of database is given below:

Syntax

exec sp_renamedb 'Old_DBName' , 'NewDBName'

where,

'OldDBName' specifies database name whose name you want to change.

'NewDBName' specifies new name which is to be given to old database name.

Change database name

To rename databse, we can use the following statement.

create database oldDBName

exec sp_renamedb 'oldDBName', 'EmployeeDetails'

Output:

rename database.jpg

Note: sp_renamedb syntax will be phased out in the future version of SQL Server. This stored procedure works for SQL Server 2005, 2008, 2008R2 and 2012.


Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.