Dark Mode
Image

SQL RENAME Database

SQL RENAME Database

In some situations, database users and administrators want to change the name of the database for some technical reasons. So, the Rename Database statement in SQL is used to change the name of the existing database.

Sometimes, the Rename Database statement is used because the developers think that the original name is not more relevant to the data of the database, or they want to give a temporary name to that database.

Syntax of Rename Database in SQL

 
  1. ALTER DATABASE old_database_name MODIFY NAME = new_database_name;  
 
  1. EXEC sp_renamedb'old_database_name' , 'new_database_name'  

Syntax of Rename Database in MySQL

 
  1. RENAME DATABASE old_database_name TO new_database_name;   

This syntax is used when we want to change the name of the database in MySQL.

Examples of Rename Database in SQL

In this article, we have taken the following two examples which will help you how to run and perform the Rename Database query in SQL:

Example 1:

Suppose we want to rename the Student Database. For this, we have to type the following query in SQL:

 
  1. ALTER DATABASE Student MODIFY NAME = College ;  

This query will change the name of the database from Student to College. To run this query, we must ensure that the database Student exists in the current database server. If not, then it will show an error in the output.

 

Comment / Reply From