Changing MS SQL Database Name with Query

To replace a database name with a query in MS SQL Server, one of the 2 ways below should be followed.

EXEC sp_renamedb {Old Database Name}, {New Database Name} or ALTER DATABASE {Old Database Name} MODIFY NAME = {New Database Name}

Examples of usage patterns are given below..

EXEC sp_renamedb 'oldDBName', 'newDBName' or ALTER DATABASE oldDBName MODIFY NAME = newDBName

Note : When the code is run, you will see that the database name has not changed in the left panel (Object Explorer). To do this, right click on the Databases folder and perform Refresh.



You May Interest

What is the Use of Dedicated Admin Connection ?

Disabling All Constants in a Table in MS SQL

What is the Difference Between VARCHAR and VARCHAR(MAX) Datatypes ...

Which TCP/IP Port Does the SQL Server Run On ?

What is Resource Governor in SQL Server ?