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 account
- 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"
--name: database name before renaming.
--new-name: new database name.
--resource-group: name of the database resource group.
--server: database server name.
Official documentation: az sql db rename.
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"