|
1 | 1 | --- |
2 | 2 | title: "SQL" |
3 | | -description: API coverage for Microsoft.Sql in LocalStack for Azure. |
| 3 | +description: Get started with Azure SQL in LocalStack for Azure. |
4 | 4 | template: doc |
5 | 5 | --- |
6 | 6 |
|
7 | 7 | import AzureFeatureCoverage from "../../../../components/feature-coverage/AzureFeatureCoverage"; |
8 | 8 |
|
| 9 | +## Introduction |
| 10 | + |
| 11 | +Azure SQL is a managed relational database service for building cloud-native applications with familiar SQL Server tooling. |
| 12 | +It supports creating logical servers, provisioning databases, and configuring operational features such as firewall access and retention policies. |
| 13 | +This makes it a common choice for transactional workloads and application backends. |
| 14 | + |
| 15 | +LocalStack for Azure lets you build and test Azure SQL workflows locally using the same CLI patterns you use in cloud environments. |
| 16 | +The supported APIs are listed in the [API Coverage](#api-coverage) section. |
| 17 | + |
| 18 | +## Getting started |
| 19 | + |
| 20 | +This guide is designed for users new to Azure SQL and assumes basic knowledge of the Azure CLI and `azlocal`. |
| 21 | + |
| 22 | +Start by enabling interception so your `az` commands are routed to LocalStack: |
| 23 | + |
| 24 | +```bash |
| 25 | +azlocal start_interception |
| 26 | +``` |
| 27 | + |
| 28 | +The following example creates a SQL server, creates a database, configures firewall access, and manages retention and encryption settings. |
| 29 | + |
| 30 | +### Create a resource group |
| 31 | + |
| 32 | +Create a resource group to contain your SQL resources: |
| 33 | + |
| 34 | +```bash |
| 35 | +az group create --name rg-sql-demo --location westeurope |
| 36 | +``` |
| 37 | + |
| 38 | +```bash title="Output" |
| 39 | +{ |
| 40 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo", |
| 41 | + "location": "westeurope", |
| 42 | + "name": "rg-sql-demo", |
| 43 | + "properties": { |
| 44 | + "provisioningState": "Succeeded" |
| 45 | + }, |
| 46 | + ... |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +### Create and inspect a SQL server |
| 51 | + |
| 52 | +Create a logical SQL server to host your databases: |
| 53 | + |
| 54 | +```bash |
| 55 | +az sql server create \ |
| 56 | + --name sqlsrvdoc85 \ |
| 57 | + --resource-group rg-sql-demo \ |
| 58 | + --location westeurope \ |
| 59 | + --admin-user lsadmin \ |
| 60 | + --admin-password "LocalstackSqlPassw0rd" |
| 61 | +``` |
| 62 | + |
| 63 | +```bash title="Output" |
| 64 | +{ |
| 65 | + "name": "UpsertLogicalServer", |
| 66 | + "operation": "UpsertLogicalServer", |
| 67 | + "status": "Succeeded", |
| 68 | + ... |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +Get the SQL server details to verify it is ready: |
| 73 | + |
| 74 | +```bash |
| 75 | +az sql server show --name sqlsrvdoc85 --resource-group rg-sql-demo |
| 76 | +``` |
| 77 | + |
| 78 | +```bash title="Output" |
| 79 | +{ |
| 80 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85", |
| 81 | + "name": "sqlsrvdoc85", |
| 82 | + "location": "westeurope", |
| 83 | + "state": "Ready", |
| 84 | + "publicNetworkAccess": "Enabled", |
| 85 | + "type": "Microsoft.Sql/servers", |
| 86 | + ... |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +### Create and query a database |
| 91 | + |
| 92 | +Create a database on the SQL server: |
| 93 | + |
| 94 | +```bash |
| 95 | +az rest --method put \ |
| 96 | + --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" \ |
| 97 | + --headers "Content-Type=application/json" \ |
| 98 | + --body '{"location":"westeurope"}' |
| 99 | +``` |
| 100 | + |
| 101 | +```bash title="Output" |
| 102 | +{ |
| 103 | + "name": "CreateLogicalDatabase", |
| 104 | + "operation": "CreateLogicalDatabase", |
| 105 | + "startTime": "2026-02-27T10:11:48.1772187108+00:00", |
| 106 | + "status": "InProgress" |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +List databases on the SQL server to confirm it was created: |
| 111 | + |
| 112 | +```bash |
| 113 | +az rest --method get \ |
| 114 | + --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" |
| 115 | +``` |
| 116 | + |
| 117 | +```bash title="Output" |
| 118 | +{ |
| 119 | + "value": [ |
| 120 | + { |
| 121 | + "name": "sqldbdoc85", |
| 122 | + "type": "Microsoft.Sql/servers/databases", |
| 123 | + "properties": { |
| 124 | + "status": "Online", |
| 125 | + ... |
| 126 | + }, |
| 127 | + ... |
| 128 | + } |
| 129 | + ] |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +### Add a firewall rule |
| 134 | + |
| 135 | +Create a firewall rule to allow client access: |
| 136 | + |
| 137 | +```bash |
| 138 | +az sql server firewall-rule create \ |
| 139 | + --resource-group rg-sql-demo \ |
| 140 | + --server sqlsrvdoc85 \ |
| 141 | + --name AllowLocal \ |
| 142 | + --start-ip-address 0.0.0.0 \ |
| 143 | + --end-ip-address 255.255.255.255 |
| 144 | +``` |
| 145 | + |
| 146 | +```bash title="Output" |
| 147 | +{ |
| 148 | + "name": "AllowLocal", |
| 149 | + "startIpAddress": "0.0.0.0", |
| 150 | + "endIpAddress": "255.255.255.255", |
| 151 | + "type": "Microsoft.Sql/servers/firewallRules", |
| 152 | + ... |
| 153 | +} |
| 154 | +``` |
| 155 | + |
| 156 | +### Configure transparent data encryption |
| 157 | + |
| 158 | +Enable transparent data encryption on the database: |
| 159 | + |
| 160 | +```bash |
| 161 | +az rest --method put \ |
| 162 | + --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" \ |
| 163 | + --headers "Content-Type=application/json" \ |
| 164 | + --body '{"properties":{"status":"Enabled"}}' |
| 165 | +``` |
| 166 | + |
| 167 | +```bash title="Output" |
| 168 | +{ |
| 169 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-sql-demo/providers/Microsoft.Sql/servers/sqlsrvdoc85/databases/sqldbdoc85/transparentDataEncryption/current", |
| 170 | + "name": "current", |
| 171 | + "type": "Microsoft.Sql/servers/databases/transparentDataEncryption", |
| 172 | + ... |
| 173 | +} |
| 174 | +``` |
| 175 | + |
| 176 | +### Configure backup retention policies |
| 177 | + |
| 178 | +Configure a short-term backup retention policy: |
| 179 | + |
| 180 | +```bash |
| 181 | +az rest --method put \ |
| 182 | + --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" \ |
| 183 | + --headers "Content-Type=application/json" \ |
| 184 | + --body '{"properties":{"retentionDays":7,"diffBackupIntervalInHours":24}}' |
| 185 | +``` |
| 186 | + |
| 187 | +```bash title="Output" |
| 188 | +{ |
| 189 | + "name": "default", |
| 190 | + "properties": { |
| 191 | + "retentionDays": 7, |
| 192 | + "diffBackupIntervalInHours": 24 |
| 193 | + }, |
| 194 | + "type": "Microsoft.Sql/servers/databases/backupShortTermRetentionPolicies", |
| 195 | + ... |
| 196 | +} |
| 197 | +``` |
| 198 | + |
| 199 | +Configure a long-term backup retention policy: |
| 200 | + |
| 201 | +```bash |
| 202 | +az rest --method put \ |
| 203 | + --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" \ |
| 204 | + --headers "Content-Type=application/json" \ |
| 205 | + --body '{"properties":{"weeklyRetention":"PT0S","monthlyRetention":"PT0S","yearlyRetention":"PT0S","weekOfYear":1}}' |
| 206 | +``` |
| 207 | + |
| 208 | +```bash title="Output" |
| 209 | +{ |
| 210 | + "name": "default", |
| 211 | + "properties": { |
| 212 | + "weeklyRetention": "PT0S", |
| 213 | + "monthlyRetention": "PT0S", |
| 214 | + "yearlyRetention": "PT0S", |
| 215 | + "weekOfYear": 1 |
| 216 | + }, |
| 217 | + "type": "Microsoft.Sql/servers/databases/backupLongTermRetentionPolicies", |
| 218 | + ... |
| 219 | +} |
| 220 | +``` |
| 221 | + |
9 | 222 | ## API Coverage |
10 | 223 |
|
11 | 224 | <AzureFeatureCoverage service="Microsoft.Sql" client:load /> |
0 commit comments