SQL Query to Rename Database
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.
CREATE DATABASE Test
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.
ALTER DATABASE Test MODIFY NAME = Example
The database name is changed from Test to Example.
Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course by GeeksforGeeks.