Azure CLI samples for Azure SQL Database
Applies to: Azure SQL Database
You can configure Azure SQL Database by using the Azure CLI.
If you don't have an Azure subscription, create an Azure free account before you begin.
Prerequisites
Use the Bash environment in Azure Cloud Shell. For more information, see Quickstart for Bash in Azure Cloud Shell.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Sign in with the Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
Samples
The following table includes links to Azure CLI script examples to manage single and pooled databases in Azure SQL Database.
Area | Description |
---|---|
Create databases | |
Create a single database | Creates a SQL Database and configures a server-level firewall rule. |
Create pooled databases | Creates elastic pools, moves pooled databases, and changes compute sizes. |
Scale databases | |
Scale a single database | Scales single database. |
Scale pooled database | Scales a SQL elastic pool to a different compute size. |
Configure geo-replication | |
Single database | Configures active geo-replication for a database in Azure SQL Database and fails it over to the secondary replica. |
Pooled database | Configures active geo-replication for a database in an elastic pool, then fails it over to the secondary replica. |
Configure failover group | |
Configure failover group | Configures a failover group for a group of databases and failover over databases to the secondary server. |
Single database | Creates a database and a failover group, adds the database to the failover group, then tests failover to the secondary server. |
Pooled database | Creates a database, adds it to an elastic pool, adds the elastic pool to the failover group, then tests failover to the secondary server. |
Back up, restore, copy, and import a database | |
Back up a database | Backs up a database in SQL Database to an Azure storage backup. |
Restore a database | Restores a database in SQL Database to a specific point in time. |
Copy a database to a new server | Creates a copy of an existing database in SQL Database in a new server. |
Import a database from a BACPAC file | Imports a database to SQL Database from a BACPAC file. |
Learn more about the single-database Azure CLI API.