Take the 2-minute tour ×

how to rename the database using query?

share|improve this question

closed as not a real question by Anton Gogolev, wallyk, Rubens Farias, sth, John Saunders Feb 15 '10 at 2:34


You need to specify which database e.g. Oracle, SQL Server, MySql and preferably also specify version. –  Andrew Feb 11 '10 at 9:21
What is your need ? –  Hugues Van Landeghem Feb 11 '10 at 18:01

4 Answers 4

SQL Server 2005 and up:

ALTER DATABASE db_name MODIFY NAME = new_db_name
share|improve this answer
You may need to set to SINGLE_USER mode first, e.g.: ALTER DATABASE [db_name] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; ALTER DATABASE [db_name] MODIFY NAME = [new_db_name]; ALTER DATABASE [new_db_name] SET MULTI_USER –  Chris Sep 18 '12 at 9:49

About what DB are we talking? Oracle, MSSQL, MySQL, SQLite.

Do you really mean the name of the database or just a table?

I belief that it's not possible to rename the actual database by a query.

share|improve this answer
what you mean - not possible to rename the actual database by a query... following query renames db in mssql ALTER DATABASE db_name MODIFY NAME = new_db_name –  Nisar Aug 19 at 4:23
@Nisar you are right. I think (and hope!) that I simply misunderstood the question. –  Rhapsody Aug 19 at 15:27

For Interbase or Firebird which are single file database : you can't make it by query.

But you can rename the database when you rename the file : so it's quite easy.

share|improve this answer
