Rename SQL Azure database?

39,766

Solution 1

Please check that you've connected to master database and you not trying to rename system database.

Please find more info here: https://msdn.microsoft.com/en-US/library/ms345378.aspx

Solution 2

Just so people don't have to search through the comments to find this... Use:

ALTER DATABASE [dbname] MODIFY NAME = [newdbname]

(Make sure you include the square brackets around both database names.)

Solution 3

You can also connect with SQL Server Management Studio and rename it in Object Explorer. I just did so and the Azure Portal reflected the change immediately.

Do this by clicking on the database name (as the rename option from the dropdown will be greyed out)

Solution 4

Connect with SQL Server Management Studio to your Azure database server, right-click on the master database and select 'New Query'. In the New Query window that will open type ALTER DATABASE [dbname] MODIFY NAME = [newdbname].

Solution 5

It's Very simple for now - Connect to DB via SQL Management Studio and Just rename as you generally doing for DB [Press F2 on DB name]. It will allow you to do this and it will immediately reflect the same.

Share:
39,766
Arun Rana
Author by

Arun Rana

Founder & Lead DevOps at Prayosys Technologies

Updated on July 05, 2022

Comments

  • Arun Rana
    Arun Rana about 2 years

    How can i rename the database in sql Azure?

    I have tried Alter database old_name {MODIFY NAME = new_name} but not worked.

    Is this feature available in SQL Azure or not?

  • dimko1
    dimko1 over 12 years
    @ArunRana what db you are connecting to?
  • Arun Rana
    Arun Rana over 12 years
    I am connected with SQL Azure database in R2 client of SQL server
  • dimko1
    dimko1 over 12 years
    when you trying to execute sql script what database is used? Please ensure that you are using master db.
  • Arun Rana
    Arun Rana over 12 years
    Alter database [APMV2.4] { MODIFY NAME [APMV2.2_Test] }
  • dimko1
    dimko1 over 12 years
    Please try this: USE master; ALTER DATABASE APMV2.4 Modify Name = APMV2,2_TEST;
  • Arun Rana
    Arun Rana over 12 years
    Msg 102, Level 15, State 1, Line 1 Incorrect syntax near '.4'.
  • Arun Rana
    Arun Rana over 12 years
    Msg 40510, Level 15, State 2, Line 1 Statement 'ALTER DATABASE' is not supported in this version of SQL Server.
  • dimko1
    dimko1 over 12 years
    This is just incorrect. Are you sure that you are connecting to right database?
  • Arun Rana
    Arun Rana over 12 years
    Yes i was wrong, i have change name from sql azure portal with login to master database and use above script, but it was unsuccessful when i was trying with R2 client. thanks
  • James Reategui
    James Reategui over 12 years
    To get this to work recap: 1) Login via web based management tool 2) Run query like: ALTER DATABASE [Blah] MODIFY NAME = [Blah-test]
  • Brian MacKay
    Brian MacKay almost 11 years
    You do have to be logged into the master database for this to work... And it isn't super obvious how to do that. From the management portal, I went into one of my databases and clicked manage, which opened up the SQL manager. From there, I couldn't change which database to log into... I had to actually log in and click log out, and only then was I able to type master as the database I wanted. Yikes. But the script works fine. :)
  • Joe
    Joe about 10 years
    Instead of logging in/out - you can just use the URL https://<YourDBServer>.database.windows.net/?langid=en-us and type 'master'. If you click the link in the portal it adds an URL parameter of #$database=<WhateverWasSelected> which pre-loads the field and makes it read-only.
  • ekkis
    ekkis almost 10 years
    that doesn't work. I get: "Msg 40508, Level 16, State 1, Line 1 USE statement is not supported to switch between databases. Use a new connection to connect to a different Database.". if I don't have the "use master" then I get "Msg 5001, Level 16, State 1, Line 1 User must be in the master database."
  • ekkis
    ekkis almost 10 years
    ah. Brian MacKay points to how to log into the master database in the comment below. +1 for him
  • Jason
    Jason over 9 years
    Thanks zacharydl, this is the easiest way if you have SSMS.
  • Sirisha Chamarthi
    Sirisha Chamarthi about 9 years
    You don't need to connect to master database in SQl DB V12. You can rename it by connecting to the database. SQL DB V12 supports more alter statements, you can check here: sqlindepth.com/alter-database-in-sql-v12
  • Fer García
    Fer García almost 9 years
    Just tried this and didn't work. ALTER DATABASE... did the trick.
  • Ogglas
    Ogglas over 7 years
    I ran this command and it worked, however I still got the following error: Msg 42019, Level 16, State 2, Line 1 ALTER DATABASE operation failed. Internal service error. Msg 0, Level 20, State 0, Line 0 A severe error occurred on the current command. The results if any should be discarded
  • Cpt. Monac
    Cpt. Monac over 7 years
    If you get the "Internal service error" references above by Ogglas, make sure to run the query on the master database.
  • David Sopko
    David Sopko over 7 years
    Rename is greyed out Sql Server Management Studio 13
  • Nick.McDermaid
    Nick.McDermaid over 6 years
    I got the internal service error when running this in the Azure Portal SQL tool. But it renamed the database anyway
  • rollsch
    rollsch over 6 years
    I get "Database "x" on server "y" is not currently available when I try that.
  • d219
    d219 over 6 years
    While rename is greyed out you can still click on the database name and you should be able to over type it (have just added this info to the answer).
  • Olaj
    Olaj over 6 years
    Worked fine for me!