Open In App

SQL Query to Rename Database

Last Updated : 13 May, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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:

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

To rename a database in MySQL use the 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 MODIDY 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:

database created

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:

database renamed

The database name is changed from Test to Example.


Previous Article
Next Article

Similar Reads

SQL Query to Rename Stored Procedure
Stored Procedure is a saved SQL code. It is created to save time as we can use it again and again without writing the whole query. In this article, we will see how to Rename a Stored Procedure. To create a Procedure:Syntax: CREATE PROCEDURE procedure_name AS SELECT * FROM table_name;SQL query whose procedure needs to be created is always written af
2 min read
How to Use SQL Query to Rename a Constraint?
In SQL, we sometimes need to rename the constraints of a table. The whole process for doing the same is demonstrated below. For this article, we will be using the Microsoft SQL Server as our database. Step 1: Create a Database. For this use the below command to create a database named GeeksForGeeks. Query: CREATE DATABASE GeeksForGeeksOutput: Step
2 min read
Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
Structured Query Language (SQL): Structured Query Language (SQL) has a specific design motive for defining, accessing and changement of data. It is considered as non-procedural, In that case the important elements and its results are first specified without taking care of the how they are computed. It is implemented over the database which is drive
2 min read
SQL Query to Add Email Validation Using Only One Query
In this article let us see how can we check for the validation of mails in the student database using MSSQL as the database server. For example, if the email is like abcdedfABCDEF...0123456@gmail.com this is the valid form of an email if it is other than this then that is said to Invalid. So, now we will discuss this concept in detail step-by-step:
2 min read
SQL Server Query to Find All Permissions/Access for All Users in a Database
There are multiple ways to list all the permissions for users present in a Database in Oracle SQL. Such ways are depicted in the below article. For this article, we will be using the Microsoft SQL Server as our database. Method 1: This method lists all the server level permissions granted to the user by the database. Here we are using the inbuilt f
2 min read
SQL Query to get first and last day of a month in a Database
In this article, we will discuss the overview of SQL query to perform an operation on database and our main focus will be on how to get the First and Last Day of a Month in a Database in SQL. Let's discuss it one by one. Introduction :Queries in SQL help us to interact with the database to get done with the database creation, updating, retrieval, a
3 min read
SQL Query to Set First Day of the Week in a Database
In this article, we are going to write a SQL script to Set the first day of the week in a Database. Below is the implementation for the same. You should have MSSQL in your server. Query in SQL - A query is a request for data or information from a database table or combination of tables. This data can be used for various purposes like Training a mod
2 min read
SQL Query to Add Ranking Positions of Rows in a Database With RANK()
In this article, we will discuss the overview of SQL function RANK and then our main focus will be on Add Ranking Positions of Rows in a Database With RANK() in SQL. Let's discuss it one by one. Overview :Generally, when max/min commands are executed, a single row is displayed as output. RANK() is an SQL function introduced in order to rank the row
2 min read
SQL Query to Add an Agent Parameter in a Database
In this article, we will learn how we add an extra or a new parameter after a table is created using ALTER command in Microsoft SQL Server in detail step-by-step: Step 1: Creating database sales by using the following SQL query: CREATE DATABASE sales; Step 2: Using the database sales by using the following SQL query: USE sales; Step 3: Creating a t
2 min read
SQL Query to Get First and Last Day of a Week in a Database
An SQL query is a single line statement of a Program written in a particular language to perform a specific task. A query consists of some pre-defined functions in SQL like SELECT, CREATE, etc. So, in this article, we will learn about SQL query to get the first and last day of a week in a database. So let's create a database first to do our task, h
2 min read
Article Tags :