Rename Database Using Stored Procedure in SQL Server 2008

Change database name using stored procedure
  • 2814

Change database name using stored procedure

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


exec sp_renamedb 'Old_DBName' , 'NewDBName'


'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'


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.


More Articles

© 2020 DotNetHeaven. All rights reserved.