Rename SQL Azure database?
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.
![Arun Rana](https://i.stack.imgur.com/HRrvl.jpg?s=256&g=1)
Comments
-
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 over 12 years@ArunRana what db you are connecting to?
-
Arun Rana over 12 yearsI am connected with SQL Azure database in R2 client of SQL server
-
dimko1 over 12 yearswhen you trying to execute sql script what database is used? Please ensure that you are using master db.
-
Arun Rana over 12 yearsAlter database [APMV2.4] { MODIFY NAME [APMV2.2_Test] }
-
dimko1 over 12 yearsPlease try this: USE master; ALTER DATABASE APMV2.4 Modify Name = APMV2,2_TEST;
-
Arun Rana over 12 yearsMsg 102, Level 15, State 1, Line 1 Incorrect syntax near '.4'.
-
Arun Rana over 12 yearsMsg 40510, Level 15, State 2, Line 1 Statement 'ALTER DATABASE' is not supported in this version of SQL Server.
-
dimko1 over 12 yearsThis is just incorrect. Are you sure that you are connecting to right database?
-
Arun Rana over 12 yearsYes 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 over 12 yearsTo 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 almost 11 yearsYou 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 about 10 yearsInstead 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 almost 10 yearsthat 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 almost 10 yearsah. Brian MacKay points to how to log into the master database in the comment below. +1 for him
-
Jason over 9 yearsThanks zacharydl, this is the easiest way if you have SSMS.
-
Sirisha Chamarthi about 9 yearsYou 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 almost 9 yearsJust tried this and didn't work. ALTER DATABASE... did the trick.
-
Ogglas over 7 yearsI 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 over 7 yearsIf you get the "Internal service error" references above by Ogglas, make sure to run the query on the master database.
-
David Sopko over 7 yearsRename is greyed out Sql Server Management Studio 13
-
Nick.McDermaid over 6 yearsI got the internal service error when running this in the Azure Portal SQL tool. But it renamed the database anyway
-
rollsch over 6 yearsI get "Database "x" on server "y" is not currently available when I try that.
-
d219 over 6 yearsWhile 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 over 6 yearsWorked fine for me!