As a part of an Azure SQL Database administration series, this post will be a follow up from the last one, where i will write about renaming Azure SQL database, 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 database, as far as i know.
- The first one is using TSQL, that requires SQL Server Management Studio. Run the following query:
ALTER DATABASE [dbname] MODIFY NAME = [newDBname]
- Rename using the SQL Server Management Studio GUI. Just right click on the database name and click Rename.
- Rename using the Azure CLI, which will be explained in details in the next steps.
- Azure subscription
- Azure SQL database
Rename an Azure SQL database
Step 1. Open Terminal and login to the Azure Portal:
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"
My two cents on this is to write the command in a script that will accept input parameter, so you can call a bash script, for example:
./rename-az-sql-db.sh --name "new-name-db"
Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on telegram.