Azure CLI samples for Azure SQL Database

Azure SQL Database can be configured using Azure CLI.

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

Use Azure Cloud Shell

Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. You can use either Bash or PowerShell with Cloud Shell to work with Azure services. You can use the Cloud Shell preinstalled commands to run the code in this article without having to install anything on your local environment.

To start Azure Cloud Shell:

Option Example/Link
Select Try It in the upper-right corner of a code block. Selecting Try It doesn't automatically copy the code to Cloud Shell. Example of Try It for Azure Cloud Shell
Go to, or select the Launch Cloud Shell button to open Cloud Shell in your browser. Launch Cloud Shell in a new window
Select the Cloud Shell button on the top-right menu bar in the Azure portal. Cloud Shell button in the Azure portal

To run the code in this article in Azure Cloud Shell:

  1. Start Cloud Shell.

  2. Select the Copy button on a code block to copy the code.

  3. Paste the code into the Cloud Shell session by selecting Ctrl+Shift+V on Windows and Linux or by selecting Cmd+Shift+V on macOS.

  4. Select Enter to run the code.

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 the Azure CLI.

The following table includes links to Azure CLI script examples for Azure SQL Database.

Create a single database and an elastic pool
Create a single database and configure a firewall rule This CLI script example creates a single Azure SQL database and configures a server-level firewall rule.
Create elastic pools and move pooled databases This CLI script example creates SQL elastic pools, and moves pooled Azure SQL databases, and changes compute sizes.
Scale a single database and an elastic pool
Scale a single database This CLI script example scales a single Azure SQL database to a different compute size after querying the size information for the database.
Scale an elastic pool This CLI script example scales a SQL elastic pool to a different compute size.
Failover groups
Add single database to failover group This CLI script creates a database, and a failover group, adds the database to the failover group and tests failover to the secondary server.

Learn more about the Single Database Azure CLI API.