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.

LocalStack for Azure lets you build and test Azure SQL workflows locally using the same CLI patterns you use in cloud environments. The supported APIs are listed in the API Coverage section.

This guide is designed for users new to Azure SQL and assumes basic knowledge of the Azure CLI and azlocal.

Start by enabling interception so your az commands are routed to LocalStack:

Terminal window
azlocal start_interception

The following example creates a SQL server, creates a database, configures firewall access, and manages retention and encryption settings.

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
{
"name": "UpsertLogicalServer",
"operation": "UpsertLogicalServer",
"status": "Succeeded",
...
}

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 rest --method put \
--url "http://management.localhost.localstack.cloud:4566/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85?api-version=2021-11-01" \
--headers "Content-Type=application/json" \
--body '{"location":"westeurope"}'
Output
{
"name": "CreateLogicalDatabase",
"operation": "CreateLogicalDatabase",
"startTime": "2026-02-27T10:11:48.1772187108+00:00",
"status": "InProgress"
}

List databases on the SQL server to confirm it was created:

Terminal window
az rest --method get \
--url "http://management.localhost.localstack.cloud:4566/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases?api-version=2021-11-01"
Output
{
"value": [
{
"name": "sqldbdoc85",
"type": "Microsoft.Sql/servers/databases",
"properties": {
"status": "Online",
...
},
...
}
]
}

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 rest --method put \
--url "http://management.localhost.localstack.cloud:4566/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85/transparentDataEncryption/current?api-version=2021-11-01" \
--headers "Content-Type=application/json" \
--body '{"properties":{"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",
"type": "Microsoft.Sql/servers/databases/transparentDataEncryption",
...
}

Configure a short-term backup retention policy:

Terminal window
az rest --method put \
--url "http://management.localhost.localstack.cloud:4566/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85/backupShortTermRetentionPolicies/default?api-version=2021-11-01" \
--headers "Content-Type=application/json" \
--body '{"properties":{"retentionDays":7,"diffBackupIntervalInHours":24}}'
Output
{
"name": "default",
"properties": {
"retentionDays": 7,
"diffBackupIntervalInHours": 24
},
"type": "Microsoft.Sql/servers/databases/backupShortTermRetentionPolicies",
...
}

Configure a long-term backup retention policy:

Terminal window
az rest --method put \
--url "http://management.localhost.localstack.cloud:4566/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85/backupLongTermRetentionPolicies/default?api-version=2021-11-01" \
--headers "Content-Type=application/json" \
--body '{"properties":{"weeklyRetention":"PT0S","monthlyRetention":"PT0S","yearlyRetention":"PT0S","weekOfYear":1}}'
Output
{
"name": "default",
"properties": {
"weeklyRetention": "PT0S",
"monthlyRetention": "PT0S",
"yearlyRetention": "PT0S",
"weekOfYear": 1
},
"type": "Microsoft.Sql/servers/databases/backupLongTermRetentionPolicies",
...
}
OperationImplemented
Page 1 of 0
Was this page helpful?