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. Cloud Shell lets you use either
PowerShell to work with Azure services. You can use the Cloud Shell pre-installed commands to run the code in this article without having to install anything on your local environment.
To launch 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:
Launch Cloud Shell.
Select the Copy button on a code block to copy the code.
Paste the code into the Cloud Shell session with Ctrl+Shift+V on Windows and Linux, or Cmd+Shift+V on macOS.
Press 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.
Single database & Elastic pools
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.
The following table includes links to Azure CLI script examples for Azure SQL Database - Managed Instance.
|Create a Managed Instance||This CLI script shows how to create a Managed Instance.|
|Update a Managed Instance||This CLI script shows how to update a Managed Instance.|
|Move a database to another Managed Instance||This CLI script shows how to restore a backup of a database from one instance to another.|