To rename a database in SQL, you can use the following steps: SQL – Rename Database
- Connect to the SQL server using a command prompt or SQL management studio.
- Use the following command to rename the database:
ALTER DATABASE old_database_name
MODIFY NAME = new_database_name;
- Make sure you have a backup of the database before renaming it.
- Once the command is executed, the database will be renamed and all the objects in it will also be renamed accordingly.
- After that you need to update the connection strings of all the applications that are connected to this database.
Please note that this process may cause some downtime or interruptions to applications that rely on the database you’re renaming.
Example
Here’s an example of how to rename a database named “old_db” to “new_db” in SQL:
ALTER DATABASE old_db
MODIFY NAME = new_db;
Please note that this command should be executed while you are connected to the SQL server and you should have appropriate permissions to execute this command. Also, please ensure that there is no active connection to the database you want to rename.
You can check the active connections and close them before renaming the database using the following command:
SELECT * FROM sys.sysprocesses WHERE dbid = DB_ID('old_db')
KILL [session_id]
where [session_id] is the session_id returned from the above query for the connection you want to close.