|
1 | 1 | --- |
2 | | -title: Block T-SQL Commands To Create Or Modify Azure SQL Resources |
| 2 | +title: "Block T-SQL Commands to Create or Modify Azure SQL Resources" |
| 3 | +titleSuffix: Azure SQL Database & Azure SQL Managed Instance |
3 | 4 | description: This article details features allowing Azure administrators to block T-SQL commands to create or modify Azure SQL Database and Azure SQL Managed Instance resources. |
4 | 5 | author: WilliamDAssafMSFT |
5 | 6 | ms.author: wiassaf |
6 | | -ms.reviewer: wiassaf, mathoma |
7 | | -ms.date: 03/10/2026 |
| 7 | +ms.reviewer: mathoma |
| 8 | +ms.date: 03/27/2026 |
8 | 9 | ms.service: azure-sql |
9 | 10 | ms.subservice: security |
10 | 11 | ms.topic: how-to |
11 | | -ROBOTS: NOINDEX |
12 | | -monikerRange: "=azuresql || =azuresql-db " |
13 | | -ms.custom: sfi-image-nochange |
| 12 | +ms.custom: |
| 13 | + - sfi-image-nochange |
| 14 | +monikerRange: "=azuresql || =azuresql-db || = azuresql-mi" |
14 | 15 | --- |
15 | 16 |
|
16 | | -# What is Block T-SQL CRUD? |
| 17 | +# How to block T-SQL CRUD |
17 | 18 |
|
18 | | -[!INCLUDE[appliesto-sqldb-sqlmi](../includes/appliesto-sqldb-sqlmi.md)] |
| 19 | +[!INCLUDE [appliesto-sqldb-sqlmi](../includes/appliesto-sqldb-sqlmi.md)] |
19 | 20 |
|
20 | | -The Block T-SQL CRUD features allow Azure administrators to block the creation or modification of Azure SQL resources through T-SQL. Two separate subscription-level preview feature flags are available: |
| 21 | +This article teaches you how to use the block T-SQL CRUD feature for Azure SQL resources. By using this feature, Azure administrators can block the creation or modification of Azure SQL resources through T-SQL. |
21 | 22 |
|
22 | | -| Preview feature flag | Scope | |
23 | | -| --- | --- | |
24 | | -| **Block T-SQL CRUD for logical servers** (`block-tsql-crud`) | Azure SQL Database (logical server) | |
25 | | -| **Block T-SQL CRUD for managed instances** (`block-tsql-mi-crud`) | Azure SQL Managed Instance | |
26 | | - |
27 | | -Each flag is registered independently per subscription. You can enable one or both depending on which Azure SQL services you need to govern. |
| 23 | +You can block T-SQL CRUD operations at the subscription level for the following resources: |
| 24 | +- The [logical server](logical-servers.md) in Azure |
| 25 | +- [Azure SQL Managed Instance](../managed-instance/sql-managed-instance-paas-overview.md) |
28 | 26 |
|
29 | 27 | ## Overview |
30 | 28 |
|
31 | | -To block creation or modification of resources through T-SQL and enforce resource management through an Azure Resource Manager template (ARM template) for a given subscription, the subscription-level preview features in the Azure portal can be used. This is particularly useful when you are using [Azure Policies](/azure/governance/policy/overview) to enforce organizational standards through ARM templates. Since T-SQL does not adhere to Azure Policies, a block on T-SQL create or modify operations can be applied. |
32 | | - |
33 | | -T-SQL CRUD operations can be blocked via the Azure portal, [PowerShell](/powershell/module/az.resources/register-azproviderfeature), or [Azure CLI](/cli/azure/feature#az-feature-register). |
34 | | - |
35 | | -## Blocked statements for Azure SQL Database |
36 | | - |
37 | | -When the **Block T-SQL CRUD for logical servers** (`block-tsql-crud`) preview feature is registered, the following T-SQL statements are blocked for Azure SQL Database resources: |
38 | | - |
39 | | -1. `CREATE DATABASE` |
40 | | -1. `DROP DATABASE` |
41 | | -1. `CREATE DATABASE ... AS COPY OF` |
42 | | -1. `ALTER DATABASE` (edition, service objective, max size, etc.) |
43 | | -1. `ALTER DATABASE ... ADD SECONDARY ON SERVER` |
44 | | -1. `ALTER DATABASE ... REMOVE SECONDARY ON SERVER` |
45 | | -1. `ALTER DATABASE ... FAILOVER` |
46 | | - |
47 | | -## Blocked statements for Azure SQL Managed Instance |
48 | | - |
49 | | -When the **Block T-SQL CRUD for managed instances** (`block-tsql-mi-crud`) preview feature is registered, the following T-SQL statements are blocked for Azure SQL Managed Instance resources: |
50 | | - |
51 | | -1. `CREATE DATABASE` |
52 | | -1. `DROP DATABASE` |
53 | | -1. Cancel in-progress `CREATE DATABASE` |
54 | | -1. `RESTORE DATABASE ... FROM URL` |
55 | | -1. `ALTER DATABASE ... ADD FILE` |
56 | | -1. `ALTER DATABASE ... MODIFY FILE` |
57 | | -1. `ALTER DATABASE ... REMOVE FILE` (on geo-replicated file) |
58 | | -1. `ALTER DATABASE tempdb ADD FILE` |
59 | | -1. `ALTER DATABASE tempdb MODIFY FILE` |
60 | | -1. `ALTER DATABASE tempdb REMOVE FILE` |
61 | | -1. `ALTER DATABASE ... SET` (compatibility level, collation, etc.) |
62 | | -1. `ALTER DATABASE ... SET ENCRYPTION ON/OFF` |
63 | | -1. `ALTER AVAILABILITY GROUP ... FAILOVER` (MI Link / Failover Group) |
64 | | -1. Failover stored procedure configuration |
65 | | -1. `DBCC TRACEON` / `DBCC TRACEOFF` (global trace flags) |
66 | | -1. `sp_configure` (SQL Agent enable/disable) |
67 | | -1. `sp_configure` / MSDTC transition to primary |
68 | | -1. MSDTC network settings (XA, LU, inbound/outbound) |
69 | | -1. Vulnerability Assessment scan trigger via T-SQL |
| 29 | +To block creation or modification of resources through T-SQL and enforce resource management through an Azure Resource Manager template (ARM template) for a given subscription, use the subscription-level preview features in the Azure portal. This approach is particularly useful when you're using [Azure Policies](/azure/governance/policy/overview) to enforce organizational standards through ARM templates. Since T-SQL doesn't adhere to Azure Policies, you can block T-SQL create or modify operations. |
| 30 | + |
| 31 | +You can block T-SQL CRUD operations through the Azure portal, [PowerShell](/powershell/module/az.resources/register-azproviderfeature), or [Azure CLI](/cli/azure/feature#az-feature-register). |
| 32 | + |
| 33 | +## Blocked statements |
| 34 | + |
| 35 | +Blocked statements differ between the logical server and SQL managed instance. |
| 36 | + |
| 37 | +### [Logical server](#tab/sqldb) |
| 38 | + |
| 39 | +When you register the **Block T-SQL CRUD for logical servers** (`block-tsql-crud`) feature, the feature blocks the following T-SQL statements for resources associated with the logical server: |
| 40 | + |
| 41 | +- `CREATE DATABASE` |
| 42 | +- `DROP DATABASE` |
| 43 | +- `CREATE DATABASE ... AS COPY OF` |
| 44 | +- `ALTER DATABASE` (edition, service objective, max size, and other settings) |
| 45 | +- `ALTER DATABASE ... ADD SECONDARY ON SERVER` |
| 46 | +- `ALTER DATABASE ... REMOVE SECONDARY ON SERVER` |
| 47 | +- `ALTER DATABASE ... FAILOVER` |
| 48 | + |
| 49 | +### [SQL managed instance](#tab/sqlmi) |
| 50 | + |
| 51 | +When you register the **Block T-SQL CRUD for managed instances** (`block-tsql-mi-crud`) feature, the feature blocks the following T-SQL statements for Azure SQL Managed Instance resources: |
| 52 | + |
| 53 | +- `CREATE DATABASE` |
| 54 | +- `DROP DATABASE` |
| 55 | +- Cancel in-progress `CREATE DATABASE` |
| 56 | +- `RESTORE DATABASE ... FROM URL` |
| 57 | +- `ALTER DATABASE ... ADD FILE` |
| 58 | +- `ALTER DATABASE ... MODIFY FILE` |
| 59 | +- `ALTER DATABASE ... REMOVE FILE` (on geo-replicated file) |
| 60 | +- `ALTER DATABASE tempdb ADD FILE` |
| 61 | +- `ALTER DATABASE tempdb MODIFY FILE` |
| 62 | +- `ALTER DATABASE tempdb REMOVE FILE` |
| 63 | +- `ALTER DATABASE ... SET` (compatibility level, collation, and other settings) |
| 64 | +- `ALTER DATABASE ... SET ENCRYPTION ON/OFF` |
| 65 | +- `ALTER AVAILABILITY GROUP ... FAILOVER` (MI Link / Failover Group) |
| 66 | +- Failover stored procedure configuration |
| 67 | +- `DBCC TRACEON` / `DBCC TRACEOFF` (global trace flags) |
| 68 | +- `sp_configure` (SQL Agent enable/disable) |
| 69 | +- `sp_configure` / MSDTC transition to primary |
| 70 | +- MSDTC network settings (XA, LU, inbound/outbound) |
| 71 | +- Vulnerability Assessment scan trigger via T-SQL |
| 72 | + |
| 73 | +--- |
70 | 74 |
|
71 | 75 | ## Permissions |
72 | 76 |
|
73 | | -In order to register or remove either feature, the Azure user must be a member of the Owner or Contributor role of the subscription. |
| 77 | +To register or remove either feature, you must be a member of the **Owner** or **Contributor** role for the subscription. |
| 78 | + |
| 79 | +<a id="register-a-block-t-sq;-crud-feature"></a> |
| 80 | + |
| 81 | +## Enable blocking T-SQL CRUD features |
| 82 | + |
| 83 | +You can enable the feature for the associated Azure SQL resource by using the Azure portal, PowerShell, or the Azure CLI. |
| 84 | + |
| 85 | +The following table lists the name of the feature for the associated Azure SQL resource: |
| 86 | + |
| 87 | +| Feature name | Scope | |
| 88 | +| --- | --- | |
| 89 | +| **Block T-SQL CRUD for logical servers** (`block-tsql-crud`) | The [logical server in Azure](logical-servers.md) | |
| 90 | +| **Block T-SQL CRUD for SQL managed instances** (`block-tsql-mi-crud`) | Azure SQL Managed Instance | |
| 91 | + |
| 92 | +Each feature is registered independently per subscription. You can enable one or both features depending on which Azure SQL services you need to govern. |
| 93 | + |
| 94 | +> [!NOTE] |
| 95 | +> Although you can enable and disable T-SQL CRUD blocking by using the **Preview feature** functionality in the Azure portal, the block T-SQL CRUD feature is generally available for both Azure SQL Database and Azure SQL Managed Instance. |
| 96 | +
|
| 97 | +### [Azure portal](#tab/azure-portal) |
| 98 | + |
| 99 | +To enable the feature for your subscription in the Azure portal, follow these steps: |
| 100 | + |
| 101 | +1. Go to your [subscription](https://portal.azure.com/#view/Microsoft_Azure_Billing/SubscriptionsBladeV2) in the Azure portal. |
| 102 | +1. Under **Settings**, select **Preview Features** to open the **Preview features** pane. |
| 103 | +1. On the **Preview features** pane, |
| 104 | + 1. Enter `CRUD` in the search box. |
| 105 | + 1. Select the checkbox for the features you want to register for the associated resource. The two features related to blocking T-SQL CRUD operations for Azure SQL resources are: |
| 106 | + - **Block T-SQL CRUD for logical servers** — for Azure SQL Database |
| 107 | + - **Block T-SQL CRUD for managed instances** — for Azure SQL Managed Instance |
| 108 | + 1. Select **Register** on the command bar to register the feature to your subscription. |
| 109 | + |
| 110 | + :::image type="content" source="media/block-crud-tsql/block-tsql-crud-register.png" alt-text="Screenshot from the Azure portal of With Block T-SQL CRUD checked, select Register."::: |
| 111 | + |
| 112 | +### [PowerShell](#tab/powershell) |
| 113 | + |
| 114 | +Use [Register-AzProviderFeature](/powershell/module/az.resources/register-azproviderfeature) to register the feature for your subscription. |
| 115 | + |
| 116 | +The following example registers the block T-SQL CRUD feature for logical servers: |
| 117 | + |
| 118 | +```powershell |
| 119 | +Register-AzProviderFeature -FeatureName "block-tsql-crud" -ProviderNamespace "Microsoft.Sql" |
| 120 | +``` |
| 121 | + |
| 122 | +The following example registers the block T-SQL CRUD feature for SQL managed instances: |
| 123 | + |
| 124 | +```powershell |
| 125 | +Register-AzProviderFeature -FeatureName "block-tsql-mi-crud" -ProviderNamespace "Microsoft.Sql" |
| 126 | +``` |
| 127 | + |
| 128 | +To check the registration status, use [Get-AzProviderFeature](/powershell/module/az.resources/get-azproviderfeature): |
| 129 | + |
| 130 | +```powershell |
| 131 | +Get-AzProviderFeature -FeatureName "block-tsql-crud" -ProviderNamespace "Microsoft.Sql" |
| 132 | +``` |
| 133 | + |
| 134 | +### [Azure CLI](#tab/azure-cli) |
74 | 135 |
|
75 | | -## Examples |
| 136 | +Use [az feature register](/cli/azure/feature#az-feature-register) to register the feature for your subscription. |
76 | 137 |
|
77 | | -The following section describes how you can register or unregister a preview feature with the Microsoft.Sql resource provider in the Azure portal. |
| 138 | +The following example registers the block T-SQL CRUD feature for logical servers: |
78 | 139 |
|
79 | | -### Register a Block T-SQL CRUD feature |
| 140 | +```azurecli |
| 141 | +az feature register --name block-tsql-crud --namespace Microsoft.Sql |
| 142 | +``` |
80 | 143 |
|
81 | | -1. Go to your subscription in the Azure portal. |
82 | | -1. Select the **Preview Features** tab. |
83 | | -1. Select the feature flag you want to enable: |
84 | | - - **Block T-SQL CRUD for logical servers** — for Azure SQL Database |
85 | | - - **Block T-SQL CRUD for managed instances** — for Azure SQL Managed Instance |
86 | | -1. In the window that opens, select **Register** to register this block with the Microsoft.Sql resource provider. |
| 144 | +The following example registers the block T-SQL CRUD feature for SQL managed instances: |
87 | 145 |
|
88 | | -:::image type="content" source="media/block-crud-tsql/block-tsql-crud-register.png" alt-text="With 'Block T-SQL CRUD' checked, select Register." lightbox="media/block-crud-tsql/block-tsql-crud-register.png"::: |
| 146 | +```azurecli |
| 147 | +az feature register --name block-tsql-mi-crud --namespace Microsoft.Sql |
| 148 | +``` |
89 | 149 |
|
90 | | -### Re-register Microsoft.Sql resource provider |
| 150 | +To check the registration status, use [az feature show](/cli/azure/feature#az-feature-show): |
91 | 151 |
|
92 | | -After you register either block feature with the Microsoft.Sql resource provider, you must re-register the Microsoft.Sql resource provider for the changes to take effect. To re-register the Microsoft.Sql resource provider: |
| 152 | +```azurecli |
| 153 | +az feature show --name block-tsql-crud --namespace Microsoft.Sql --output table |
| 154 | +``` |
93 | 155 |
|
94 | | -1. Go to your subscription in the Azure portal. |
| 156 | +--- |
| 157 | + |
| 158 | +## Re-register the Microsoft.Sql resource provider |
| 159 | + |
| 160 | +After you register either block feature with the Microsoft.Sql resource provider, you must re-register the Microsoft.Sql resource provider for the changes to take effect. |
| 161 | + |
| 162 | +> [!NOTE] |
| 163 | +> The re-registration step is mandatory for the T-SQL block to be applied to your subscription. |
| 164 | +
|
| 165 | +### [Azure portal](#tab/azure-portal) |
| 166 | + |
| 167 | +To re-register the Microsoft.Sql resource provider in the Azure portal, follow these steps: |
| 168 | + |
| 169 | +1. Go to your [subscription](https://portal.azure.com/#view/Microsoft_Azure_Billing/SubscriptionsBladeV2) in the Azure portal. |
95 | 170 | 1. Select the **Resource Providers** tab. |
96 | | -1. Search and select **Microsoft.Sql** resource provider. |
| 171 | +1. Search for and select the **Microsoft.Sql** resource provider. |
97 | 172 | 1. Select **Re-register**. |
98 | 173 |
|
99 | | -> [!NOTE] |
100 | | -> The re-registration step is mandatory for the T-SQL block to be applied to your subscription. |
| 174 | +:::image type="content" source="media/block-crud-tsql/block-tsql-crud-re-register.png" alt-text="Screenshot of the Azure portal showing how to re-register the Microsoft.Sql resource provider."::: |
| 175 | + |
| 176 | +### [PowerShell](#tab/powershell) |
| 177 | + |
| 178 | +Use [Register-AzResourceProvider](/powershell/module/az.resources/register-azresourceprovider) to re-register the Microsoft.Sql resource provider: |
| 179 | + |
| 180 | +```powershell |
| 181 | +Register-AzResourceProvider -ProviderNamespace "Microsoft.Sql" |
| 182 | +``` |
| 183 | + |
| 184 | +### [Azure CLI](#tab/azure-cli) |
| 185 | + |
| 186 | +Use [az provider register](/cli/azure/provider#az-provider-register) to re-register the Microsoft.Sql resource provider: |
| 187 | + |
| 188 | +```azurecli |
| 189 | +az provider register --namespace Microsoft.Sql |
| 190 | +``` |
| 191 | + |
| 192 | +--- |
101 | 193 |
|
102 | | -:::image type="content" source="media/block-crud-tsql/block-tsql-crud-re-register.png" alt-text="Screenshot of the Azure portal showing how to re-register the Microsoft.Sql resource provider." lightbox="media/block-crud-tsql/block-tsql-crud-re-register.png"::: |
| 194 | +## Remove Block T-SQL CRUD |
103 | 195 |
|
104 | | -<a id="removing-block-t-sql-crud"></a> |
| 196 | +To remove the block on T-SQL create or modify operations from your subscription, first unregister the previously registered T-SQL block feature. Then, [re-register](#re-register-the-microsoftsql-resource-provider) the Microsoft.Sql resource provider for the removal to take effect. |
105 | 197 |
|
106 | | -### Remove Block T-SQL CRUD |
| 198 | +### [Azure portal](#tab/azure-portal) |
107 | 199 |
|
108 | | -To remove the block on T-SQL create or modify operations from your subscription, first unregister the previously registered T-SQL block. Then, re-register the Microsoft.Sql resource provider as shown above for the removal of T-SQL block to take effect. |
| 200 | +To unregister the feature in the Azure portal: |
| 201 | + |
| 202 | +1. Go to your [subscription](https://portal.azure.com/#view/Microsoft_Azure_Billing/SubscriptionsBladeV2) in the Azure portal. |
| 203 | +1. Under **Settings**, select **Preview Features**. |
| 204 | +1. Select the feature you want to unregister. |
| 205 | +1. Select **Unregister**. |
| 206 | + |
| 207 | +### [PowerShell](#tab/powershell) |
| 208 | + |
| 209 | +Use [Unregister-AzProviderFeature](/powershell/module/az.resources/unregister-azproviderfeature) to unregister the feature: |
| 210 | + |
| 211 | +```powershell |
| 212 | +Unregister-AzProviderFeature -FeatureName "block-tsql-crud" -ProviderNamespace "Microsoft.Sql" |
| 213 | +``` |
| 214 | + |
| 215 | +For SQL managed instances: |
| 216 | + |
| 217 | +```powershell |
| 218 | +Unregister-AzProviderFeature -FeatureName "block-tsql-mi-crud" -ProviderNamespace "Microsoft.Sql" |
| 219 | +``` |
| 220 | + |
| 221 | +After unregistering, re-register the resource provider: |
| 222 | + |
| 223 | +```powershell |
| 224 | +Register-AzResourceProvider -ProviderNamespace "Microsoft.Sql" |
| 225 | +``` |
| 226 | + |
| 227 | +### [Azure CLI](#tab/azure-cli) |
| 228 | + |
| 229 | +Use [az feature unregister](/cli/azure/feature#az-feature-unregister) to unregister the feature. |
| 230 | + |
| 231 | +The following example unregisters the feature for logical servers: |
| 232 | + |
| 233 | +```azurecli |
| 234 | +az feature unregister --name block-tsql-crud --namespace Microsoft.Sql |
| 235 | +``` |
| 236 | +The following example unregisters the feature for SQL managed instances: |
| 237 | + |
| 238 | +```azurecli |
| 239 | +az feature unregister --name block-tsql-mi-crud --namespace Microsoft.Sql |
| 240 | +``` |
| 241 | + |
| 242 | +After unregistering the feature, use the following command to re-register the resource provider: |
| 243 | + |
| 244 | +```azurecli |
| 245 | +az provider register --namespace Microsoft.Sql |
| 246 | +``` |
| 247 | + |
| 248 | +--- |
109 | 249 |
|
110 | 250 | ## Related content |
111 | 251 |
|
|
0 commit comments