In the real world, there is very minimal chance when we need to rename database but still renaming database is a very valid scenario in real time.

Today we will try to rename databases in some of the most used Databases of the world.


In this section, we will see how different databases provides the feature of renaming a database. So let’s start with the following set of databases.

  1. PostgreSQL
  2. MySQL
  3. SQLServer

We will try to understand database renaming in each of the above mentioned DBs one by one.


Let us try to rename a database in PostgreSQL.

Suppose the database that you want to rename is TestDB.

First, disconnect from the database that you want to rename by connecting to another database, we will connect to Postgres database.
By connecting to another database, you are automatically disconnected from the database to which you connected.

Before renaming any database it is always good to check if the database has an active connection.

We will also check in PostgreSQL if the database that we want to rename has any active connections.

Output: –

PostgreSQL Check Connection

As we see that the database has only one connection. If the database has many connections it is better to inform the respective user about the rename.

After that, rename the TestDB database to NewTestDB using the ALTER DATABASE RENAME TO statement as follows:


PostgreSQL rename database


In the earlier version of MySQL rename database was done through a simple SQL command. But, due to security issues, the feature is revoked from the latest versions.

We can create a dumped copy, then create a new DB and then re-import from the dumbed copy.

SQL Command for Dump copy

SQL Command for creating new DB

SQL Command for Import

The above is one such solution for renaming a DB in MySQL

Also for Unix, database names are case-sensitive so please make sure that appropriate case is used.


We will now use SQLServer to rename a database. Let us rename TestDB using SQL Server Management Studio.

Please find below the steps to be followed to rename the database.

  1. Connect to the Database in the Object Explorer.
  2. We will try to make sure that there is no more connection to the DB before renaming.
  3. Set the connection to single user mode.
  4. Right Click on the database and click on properties.
  5. In the Database Properties box, click the Options page.
  6. From the Restrict Access option, select Single.
  7. If other users are connected to the database, an Open Connections message will appear. To change the property and close all other connections, click Yes.
  8. Now right click the DB and click on Rename.
  9. Enter the new database name and click on OK button.
  10. SQLServer_Properties


SQLServer Properties



SQLServer Properties Rename


SQLServer Rename

Once the rename process is complete please revert the SINGLE USER mode.

By admin

Leave a Reply

%d bloggers like this: