SQL Query to Rename Database
Last Updated :
08 Oct, 2021
ALTER SQL command is a DDL (Data Definition Language) statement. ALTER is used to update the structure of the table in the database (like add, delete, modify the attributes of the tables in the database).In this article, we will look at how to rename a database in the SQL server by using the ALTER-Modify keyword. To rename the database we need to create the database first. So, let us create it.
Step 1: Creating Database
We are creating the database using CREATE query.
Step 2: CREATE query
The CREATE query is used to create a new database.
Query:
CREATE DATABASE Test
Output:
Step 3: Rename Database
For this, we need to use the ALTER command. ALTER keyword is used to add, delete/drop or modify columns in the existing table. It is also used to add and drop various constraints on the existing table.
- Renaming means we are modifying the data.
- Hence, we will use ALTER – MODIFY.
Query:
ALTER DATABASE Test MODIFY NAME = Example
Output:
The database name is changed from Test to Example.
Share your thoughts in the comments
Please Login to comment...