Skip to content
Get Started for Free

SQL

Azure SQL is a managed relational database service for building cloud-native applications with familiar SQL Server tooling. It supports creating logical servers, provisioning databases, and configuring operational features such as firewall access and retention policies. This makes it a common choice for transactional workloads and application backends. For more information, see What is Azure SQL Database?.

LocalStack for Azure provides a local environment for building and testing applications that make use of Azure SQL Database. The supported APIs are listed in the API Coverage section.

This guide is designed for users new to Azure SQL Database and assumes basic knowledge of the Azure CLI and azlocal. The following example creates a SQL server and database, configures firewall access, and defines retention and encryption settings.

Launch LocalStack using your preferred method. For more information, see Introduction to LocalStack for Azure. Once the container is running, enable Azure CLI interception by running:

Terminal window
azlocal start-interception

This command points the az CLI away from the public Azure management REST API and toward the LocalStack for Azure emulator API. To revert this configuration, run:

Terminal window
azlocal stop-interception

This reconfigures the az CLI to send commands to the official Azure management REST API.

Create a resource group to contain your SQL resources:

Terminal window
az group create --name rg-sql-demo --location westeurope
Output
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo",
"location": "westeurope",
"name": "rg-sql-demo",
"properties": {
"provisioningState": "Succeeded"
},
...
}

Create a logical SQL server to host your databases:

Terminal window
az sql server create \
--name sqlsrvdoc85 \
--resource-group rg-sql-demo \
--location westeurope \
--admin-user lsadmin \
--admin-password "LocalstackSqlPassw0rd"
Output
{
"administratorLogin": "lsadmin",
...
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85",
...
"location": "westeurope",
...
"name": "sqlsrvdoc85",
...
"type": "Microsoft.Sql/servers",
...
}

Get the SQL server details to verify it is ready:

Terminal window
az sql server show --name sqlsrvdoc85 --resource-group rg-sql-demo
Output
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85",
"name": "sqlsrvdoc85",
"location": "westeurope",
"state": "Ready",
"publicNetworkAccess": "Enabled",
"type": "Microsoft.Sql/servers",
...
}

Create a database on the SQL server:

Terminal window
az sql db create \
--name sqldbdoc85 \
--resource-group rg-sql-demo \
--server sqlsrvdoc85 \
--service-objective S0 \
--compute-model Provisioned
Output
{
...
"catalogCollation": "SQL_Latin1_General_CP1_CI_AS",
"collation": "SQL_Latin1_General_CP1_CI_AS",
"creationDate": "2026-03-24T09:32:54.177434+00:00",
"currentBackupStorageRedundancy": "Geo",
"currentServiceObjectiveName": "GP_Gen5_2",
"currentSku": {
"capacity": 2,
"family": "Gen5",
"name": "S0",
"size": null,
"tier": "GeneralPurpose"
},
"databaseId": "62951a4b-e3b7-41ce-b7e7-1d4860801828",
...
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85",
...
"name": "sqldbdoc85",
...
"sku": {
"capacity": 2,
"family": "Gen5",
"name": "S0",
"size": null,
"tier": "GeneralPurpose"
},
...
"status": "Online",
...
}

Verify the database status to confirm successful creation:

Terminal window
az sql db show \
--name sqldbdoc85 \
--resource-group rg-sql-demo
Output
{
...
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85",
...
"name": "sqldbdoc85",
...
"status": "Online",
...
}

List the databases on the SQL server:

Terminal window
az sql db list \
--resource-group rg-sql-demo \
--server sqlsrvdoc85
Output
[
{
...
"name": "master",
...
},
{
...
"name": "sqldbdoc85",
...
}
]

Create a firewall rule to allow client access:

Terminal window
az sql server firewall-rule create \
--resource-group rg-sql-demo \
--server sqlsrvdoc85 \
--name AllowLocal \
--start-ip-address 0.0.0.0 \
--end-ip-address 255.255.255.255
Output
{
"name": "AllowLocal",
"startIpAddress": "0.0.0.0",
"endIpAddress": "255.255.255.255",
"type": "Microsoft.Sql/servers/firewallRules",
...
}

Enable transparent data encryption on the database:

Terminal window
az sql db tde set \
--database sqldbdoc85 \
--server sqlsrvdoc85 \
--resource-group rg-sql-demo \
--status Enabled
Output
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85/transparentDataEncryption/current",
"name": "current",
"resourceGroup": "rg-sql-demo",
...
"state": "Enabled",
"type": "Microsoft.Sql/servers/databases/transparentDataEncryption"
}

Configure a short-term backup retention policy:

Terminal window
az sql db str-policy set \
--name sqldbdoc85 \
--server sqlsrvdoc85 \
--resource-group rg-sql-demo \
--retention-days 7 \
--diffbackup-hours 24
Output
{
"diffBackupIntervalInHours": 24,
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85/backupShortTermRetentionPolicies/default",
"name": "default",
"resourceGroup": "rg-sql-demo",
"retentionDays": 7,
"type": "Microsoft.Sql/servers/databases/backupShortTermRetentionPolicies"
}

Configure a long-term backup retention policy:

Terminal window
az sql db ltr-policy set \
--name sqldbdoc85 \
--server sqlsrvdoc85 \
--resource-group rg-sql-demo \
--weekly-retention "P4W" \
--monthly-retention "P12M" \
--yearly-retention "P5Y" \
--week-of-year 16
Output
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85/backupLongTermRetentionPolicies/default",
"monthlyRetention": "P12M",
"name": "default",
"resourceGroup": "rg-sql-demo",
"timeBasedImmutability": null,
"timeBasedImmutabilityMode": null,
"type": "Microsoft.Sql/servers/databases/backupLongTermRetentionPolicies",
"weekOfYear": 16,
"weeklyRetention": "P4W",
"yearlyRetention": "P5Y"
}

The Azure SQL emulator supports the following features:

  • Server lifecycle management: Create, update, delete, get, and list logical SQL servers.
  • Database CRUD: Create, update, delete, get, list, and rename databases on a logical server.
  • Firewall rules: Create, update, delete, get, and list server-level firewall rules.
  • Transparent data encryption (TDE): Create or update, get, and list TDE configurations per database.
  • Short-term backup retention policies: Create or update, get, update, and list short-term retention policies per database.
  • Long-term backup retention policies: Create or update, get, and list long-term retention policies per database.
  • Database security alert policies: Create or update, get, and list security alert policies per database.
  • Server connection policies: Create or update, get, and list connection policies per server.
  • SQL vulnerability assessments: Create or update, get, and list vulnerability assessment settings per server.
  • Database schema introspection: Get and list schemas, tables, and columns by querying the live SQL Server instance.
  • Server name availability check: Check whether a server name is available for use.
  • Restorable dropped databases: Get and list restorable dropped databases (stub: always returns an empty list).
  • Replication links: List replication links for a database (stub: always returns an empty list).
  • Asynchronous provisioning: Server and database creation use async operations with polling headers, matching real Azure behavior.
  • No data persistence across restarts: SQL Server containers are ephemeral. All databases, schemas, and data are lost when the LocalStack emulator is stopped or restarted.
  • Backup retention policies are metadata-only: Short-term and long-term retention policies are stored but no actual backup or restore operations are performed.
  • Transparent data encryption is metadata-only: TDE settings are stored but no actual encryption is applied to the database files.
  • Security alert policies are metadata-only: Alert policies are stored but do not trigger notifications or log monitoring.
  • Vulnerability assessments are metadata-only: Assessment settings are stored but no scans are executed.
  • Server connection policies are metadata-only: Connection policies are stored but do not affect network behavior.
  • Replication links always empty: No geo-replication or active replication is supported.
  • Elastic pools, failover groups, and geo-replication are not supported: These features are not implemented.
  • MSSQL EULA acceptance required: The MSSQL_ACCEPT_EULA environment variable must be set to Y before creating any SQL server.

The behavior of the Azure SQL emulator can be customized using the environment variables listed below.

VariableDescriptionTypeDefault
MSSQL_ACCEPT_EULAAccept the Microsoft SQL Server End-User License Agreement. Must be set to Y to create SQL servers.String(unset)
ALLOW_MULTIPLE_SQL_SERVER_DEPLOYMENTSAllow provisioning more than one SQL Server Docker container. Set to 1 or true to enable.Boolean0

The following sample demonstrates how to use Azure SQL Database with LocalStack for Azure:

OperationImplemented
Page 1 of 0
Was this page helpful?