Microsoft Docs

Azure SQL Virtual Machine CLI Reference

This document provides a comprehensive reference for the Azure Command-Line Interface (CLI) commands used to manage Azure SQL virtual machines.

Overview

The Azure CLI provides a robust set of tools for managing Azure resources, including SQL Server deployed on Azure Virtual Machines. These commands allow you to automate the deployment, configuration, and management of your SQL VM workloads.

Prerequisites

Commands

Create

Commands for creating new Azure SQL Virtual Machines.

az sql vm create --name <vm-name> --resource-group <resource-group-name> --location <location> --image <vm-image> ...

Key parameters include:

  • --name: The name of the SQL virtual machine.
  • --resource-group: The name of the resource group.
  • --location: The Azure region for the VM.
  • --image: The SQL Server VM image to use (e.g., SQL2019-WS2019).

Configure

Commands for configuring existing SQL Virtual Machines.

az sql vm configure --name <vm-name> --resource-group <resource-group-name> --sql-edition <edition> ...

Example configurations include setting the SQL Server edition, network settings, and storage options.

Manage

Commands for managing the lifecycle and properties of SQL Virtual Machines.

az sql vm show --name <vm-name> --resource-group <resource-group-name>

This includes commands to start, stop, restart, and retrieve details about your SQL VMs.

Delete

Commands for deleting Azure SQL Virtual Machines.

az sql vm delete --name <vm-name> --resource-group <resource-group-name>

Warning: This action is irreversible and will delete the SQL VM and its associated resources.

Examples

Replace placeholders like <resource-group-name> with your actual values.

Create a SQL Server 2019 VM on Windows Server 2019

az sql vm create \
  --name mySqlVm \
  --resource-group myResourceGroup \
  --location eastus \
  --image SQL2019-WS2019 \
  --admin-username azureuser \
  --admin-password 'MyComplexPassword123!' \
  --sql-edition Enterprise \
  --storage-type Premium_LRS \
  --vnet-name myVnet \
  --subnet mySubnet

Show details of a SQL VM

az sql vm show \
  --name mySqlVm \
  --resource-group myResourceGroup

Delete a SQL VM

az sql vm delete \
  --name mySqlVm \
  --resource-group myResourceGroup

Parameters

The following table lists common parameters used across various az sql vm commands. Refer to individual command documentation for specific parameter details.

Parameter Description Required
--name or -n The name of the SQL virtual machine. Yes (for most commands)
--resource-group or -g The name of the resource group. Yes
--location or -l The Azure region. Yes (for create)
--image Specifies the SQL Server VM image (e.g., SQL2019-WS2019, SQL2017-WS2016). Yes (for create)
--sql-edition The edition of SQL Server (e.g., Enterprise, Standard, Web). No
--admin-username The administrator username for the VM. Yes (for create)
--admin-password The administrator password for the VM. Yes (for create, unless using SSH keys)
--storage-type The type of storage for data disks (e.g., Standard_LRS, Premium_LRS). No

Output

The Azure CLI typically returns JSON output for commands that retrieve information (e.g., show). Commands that perform actions (e.g., create, delete) will return status messages indicating success or failure. You can use the --output parameter (e.g., --output table, --output tsv) to format the output.