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.

Open Azure Cloud Shell

Azure Cloud Shell is an interactive shell environment hosted in Azure and used through your browse. Azure Cloud Shell allows you to use either bash or PowerShell shells to run a variety of tools to work with Azure services. Azure Cloud Shell comes pre-installed with the commands to allow you to run the content of this article without having to install anything on your local environment.

To run any code contained in this article on Azure Cloud Shell, open a Cloud Shell session, use the Copy button on a code block to copy the code, and paste it into the Cloud Shell session with Ctrl+Shift+V on Windows and Linux, or Cmd+Shift+V on macOS. Pasted text is not automatically executed, so press Enter to run code.

You can launch Azure Cloud Shell with:

Option Example/Link
Select Try It in the upper-right corner of a code block. This doesn't automatically copy text to Cloud Shell. Example of Try It for Azure Cloud Shell
Open Azure Cloud Shell in your browser.
Select the Cloud Shell button on the menu in the upper-right corner of the Azure portal. Cloud Shell button in the Azure 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 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.

Learn more about the Single Database Azure CLI API.

Managed Instance

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.

Learn more about the Managed Instance Azure CLI API and find additional examples here.