Rename SQL Azure database?

TsqlAzureAzure Sql-DatabaseRename

Tsql Problem Overview


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?

Tsql Solutions


Solution 1 - Tsql

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 2 - Tsql

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 3 - Tsql

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 - Tsql

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 - Tsql

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.

Solution 6 - Tsql

I can confirm the

ALTER DATABASE [oldname] MODIFY NAME = [newname];

works without connecting to master first BUT if you are renaming a restored Azure database; don't miss the space before the final hyphen

ALTER DATABASE [oldname_2017-04-23T09 -17Z] MODIFY NAME = [newname];

And be prepared for a confusing error message in the Visual Studio 2017 Message window when executing the ALTER command

Msg 0, Level 20, State 0, Line 0
A severe error occurred on the current command.  The results, if any, should be discarded.

Solution 7 - Tsql

You can easily do it from SQL Server Management Studio, Even from the community edition.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionArun RanaView Question on Stackoverflow
Solution 1 - TsqlBrettView Answer on Stackoverflow
Solution 2 - Tsqldimko1View Answer on Stackoverflow
Solution 3 - TsqlzacharydlView Answer on Stackoverflow
Solution 4 - TsqlOrlinView Answer on Stackoverflow
Solution 5 - TsqlAbhishek GuptaView Answer on Stackoverflow
Solution 6 - TsqlRobertView Answer on Stackoverflow
Solution 7 - TsqlAli SufyanView Answer on Stackoverflow