Azure CLI samples for Azure SQL Database
Azure SQL Database can be configured using Azure CLI.
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:
|Select Try It in the upper-right corner of a code block. Selecting Try It doesn't automatically copy the code to Cloud Shell.|
|Go to https://shell.azure.com, or select the Launch Cloud Shell button to open Cloud Shell in your browser.|
|Select the Cloud Shell button on the top-right menu bar in the Azure portal.|
To run the code in this article in Azure Cloud Shell:
Start Cloud Shell.
Select the Copy button on a code block to copy the code.
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.
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.|
|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.