Use CLI to scale a SQL elastic pool in Azure SQL Database

This Azure CLI script example creates SQL elastic pools, moves pooled databases, and changes elastic pool performance levels.

If you don't have an Azure subscription, create a free account before you begin.

Open Azure Cloud Shell

Azure Cloud Shell is a free, interactive shell that you can use to run the steps in this article. Common Azure tools are preinstalled and configured in Cloud Shell for you to use with your account. Just select the Copy button to copy the code, paste it in Cloud Shell, and then press Enter to run it. There are a few ways to open Cloud Shell:

Select Try It in the upper-right corner of a code block. Cloud Shell in this article
Open Cloud Shell in your browser.
Select the Cloud Shell button on the menu in the upper-right corner of the Azure portal. Cloud Shell in the portal

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.

Sample script


# 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 pool
az sql elastic-pools create \
	--resource-group myResourceGroup \
	--location westeurope  \
	--server $servername \
	--name samplepool \
	--dtu 50 \
	--database-dtu-max 20

# Create two database in the pool
az sql db create \
	--resource-group myResourceGroup \
	--server $servername \
	--name myFirstSampleDatabase \
	--elastic-pool-name samplepool
az sql db create \
	--resource-group myResourceGroup \
	--server $servername \
	--name mySecondSampleDatabase \
	--elastic-pool-name samplepool

# Scale up to the pool to 100 eDTU
az sql elastic-pools update \
	--resource-group myResourceGroup \
	--server $servername \
	--name samplepool \
	--set dtu=100

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

Script explanation

This script uses the following commands to create a resource group, logical server, SQL Database, and firewall rules. Each command in the table links to command specific documentation.

Command Notes
az group create Creates a resource group in which all resources are stored.
az sql server create Creates a logical server that hosts the SQL Database.
az sql elastic-pools create Creates an elastic database pool within the logical server.
az sql db create Creates the SQL Database in the logical server.
az sql elastic-pools update Updates an elastic database pool, in this example changes the assigned eDTU.
az group delete Deletes a resource group including all nested resources.

Next steps

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.