Skip to content

SQL Query to Rename Database

To rename a database in SQL use the ALTER DATABASE Statement with MODIFY NAME clause.

The ALTER command in SQL is used to make changes to a table or database. In this article, we will learn how to use the ALTER DATABASE statement with the MODIFY NAME clause to rename a database.

How to Rename Database in SQL ?

To change the name of a database in SQL, use the syntax:

Query:

ALTER DATABASE [current_database_name] MODIFY NAME = [new_database_name];

To rename a database in MySQL use the query:

Query:

RENAME DATABASE [current_database_name] TO [new_database_name];

Note

SQL RENAME DATABASE statement is used in MySQL, and for other SQL distributions, we need to use ALTER DATABASE statement with MODIFY NAME clause.

SQL Rename Database Example

Let’s look at an example of how to rename a database in SQL.

First, we will create a database which will be renamed in the example:

Query:

CREATE DATABASE Test;

Output:

Create Database

Rename database in SQL Example

In this example, we will use the ALTER command with MODIFY NAME clause to rename the database.

Query:

ALTER DATABASE Test MODIFY NAME = Example

Output:

Rename Database

The database name is changed from Test to Example.