Renaming a database in SQL Server is done to update or change the database name without affecting its data or structure. It is used to:
- Change the database name for better identification.
- Maintain consistency with project or application requirements.
- Organize databases during migrations or updates.
Query:
ALTER DATABASE old_database_name
MODIFY NAME = new_database_name;
Step 1: Create a Database
First, create a new database using the CREATE DATABASE statement.
CREATE DATABASE Test;Output:

- The test database is created.
Step 2: Rename Database in SQL Server
In this example, we will use the ALTER command with MODIFY NAME clause to rename the database in SQL Server
ALTER DATABASE Test MODIFY NAME = Example;Output:

- The database name is changed from Test to Example.
Troubleshooting Database Rename Issues
- Database in use: Close all active connections before renaming.
- Permission issue: Ensure you have admin or required privileges.
- Name rules: Follow DBMS naming conventions and avoid reserved words.