SQL RENAME Database
The SQL RENAME DATABASE statement is used to change the name of an existing database. Renaming a database can be useful in situations where the original name is no longer relevant or if you want to standardize naming conventions.
Syntax: RENAME DATABASE old_database_name TO new_database_name;
Renaming a database requires administrative privileges, and you must ensure that no active connections are using the database when performing this operation.
Code Example
RENAME DATABASE SchoolDB TO NewSchoolDB;
Output
The RENAME DATABASE
statement allows you to update the database's name without needing to recreate it, preserving all its contents.
Important Notes:
- The RENAME DATABASE
command is not supported in all RDBMS. For example, MySQL requires workarounds, as this command may not work directly.
- Ensure no active users or connections are using the database before renaming it.