azure,

How to rename an Azure SQL database using Azure CLI

Oct 14, 2019 · 1 min read · Post a comment

As a part of an Azure SQL Database administration series, this post will be a followup from the last one, where I will write about renaming Azure SQL databases, which is kind of a common scenario for those who work as a DevOps/SysOps cloud engineer.

There are currently three ways to rename an Azure SQL databases, as far as I know.

  1. The first one is using TSQL, that requires SQL Server Management Studio. Run the following query:
    ALTER DATABASE [dbname] MODIFY NAME = [newDBname]
    
  2. Rename using the SQL Server Management Studio GUI. Just right-click on the database name and click Rename.
  3. Rename using the Azure CLI, which will be explained in details in the next steps.

Prerequisites

  • Azure subscription
  • Azure SQL database

Rename an Azure SQL database

Step 1. Open Terminal and login to the Azure Portal.

az login

It will open a new window using the default browser where you will be prompted for email and password.

Step 2. Rename the database using the following command:

az sql db rename --name "myfirstazuresqldb" --new-name "new-database-name" --resource-group "azure-sql-db-rg" --server "devcoopsdbserver"

Conclusion

You could even write the command in a bash script that will accept input parameter, for instance:

./rename-az-sql-db.sh --name "new-name-db"

Conclusion

Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.