This Azure CLI script example scales a single Azure SQL database to a different performance level after querying the size information of the database.
If you don't have an Azure subscription, create a free account before you begin.
Launch Azure Cloud Shell
The Azure Cloud Shell is a free Bash shell that you can run directly within the Azure portal. It has the Azure CLI preinstalled and configured to use with your account. Click the Cloud Shell button on the menu in the upper-right of the Azure portal.
The button launches an interactive shell that you can use to run all of the steps in this topic:
If you choose to install and use the CLI locally, this topic requires that you are running the Azure CLI version 2.0 or later. Run
az --version to find the version. If you need to install or upgrade, see Install Azure CLI 2.0.
#!/bin/bash # Set an admin login and password for your database export adminlogin=ServerAdmin export password=ChangeYourAdminPassword1 # the logical server name has to be unique in the system export servername=server-$RANDOM # Create a resource group az group create \ --name myResourceGroup \ -location westeurope # Create a server az sql server create \ --name $servername \ --resource-group myResourceGroup \ --location westeurope \ --admin-user $adminlogin \ --admin-password $password # Create a database az sql db create \ --resource-group myResourceGroup \ --server $servername \ --name mySampleDatabase \ --service-objective S0 # Monitor database size az sql db list-usages \ --name mySampleDatabase \ --resource-group myResourceGroup \ --name $servername # Scale up database to S1 performance level (create command executes update if DB already exists) az sql db create \ --resource-group myResourceGroup \ --server $servername \ --name mySampleDatabase \ --service-objective S1
Clean up deployment
After the script sample has been run, the following command can be used to remove the resource group and all resources associated with it.
az group delete --name myResourceGroup
This script uses the following commands. Each command in the table links to command specific documentation.
|az group create||Creates a resource group in which all resources are stored.|
|az sql server create||Creates a logical server that hosts a database.|
|az sql db show-usage||Shows the size usage information for a database.|
|az sql db update||Updates database properties (such as the service tier or performance level) or moves a database into, out of, or between elastic pools.|
|az group delete||Deletes a resource group including all nested resources.|
For more information on the Azure CLI, see Azure CLI documentation.
Additional SQL Database CLI script samples can be found in the Azure SQL Database documentation.