Apply an Azure Resource Manager Delete lock / CanNotDelete lock directly to the Azure SQL database resource db1.
Microsoft states that Azure resource locks can be applied at subscription, resource group, or resource scope to protect resources from accidental deletion or modification. In the Azure portal, the lock types are shown as Delete and Read-only; in CLI/PowerShell, they are called CanNotDelete and ReadOnly. A CanNotDelete/Delete lock allows users to read and modify the resource, but prevents deletion.
Azure Portal Method — Recommended for Simulation
Step 1: Open the database resource
Sign in to the Azure portal.
In the search bar, search for SQL databases.
Select the database named db1.
Make sure you select the database resource itself, not only the SQL logical server.
Step 2: Open Locks
In the left menu of db1, scroll to Settings.
Select Locks.
Select Add.
Step 3: Create the delete lock
Configure the lock as follows:
Setting
Value
Lock name
PreventDelete-db1
Lock type
Delete
Notes
Prevent accidental deletion of db1
Then select OK or Save.
In the portal, choose Delete, not Read-only. A Read-only lock is too restrictive because it can block management updates. For this task, the requirement is only to stop accidental deletion, so Delete / CanNotDelete is the correct lock type. Microsoft confirms that CanNotDelete prevents deletion but still permits reading and modifying the resource.
Step 4: Verify the lock
Stay on the db1 database page.
Go back to Locks.
Confirm the lock exists with:
Name: PreventDelete-db1
Lock type: Delete
The task is complete once db1 has a Delete lock applied.
PowerShell Method
Use this if the lab provides Azure PowerShell.
New-AzResourceLock `
-LockLevel CanNotDelete `
-LockName " PreventDelete-db1 " `
-LockNotes " Prevent accidental deletion of db1 " `
-ResourceGroupName " < resource-group-name > " `
-ResourceName " < sql-server-name > /db1 " `
-ResourceType " Microsoft.Sql/servers/databases "
Microsoft’s New-AzResourceLock documentation includes an Azure SQL Database example using resource type Microsoft.Sql/servers/databases and resource name format serverName/databaseName.
Example format:
New-AzResourceLock `
-LockLevel CanNotDelete `
-LockName " PreventDelete-db1 " `
-LockNotes " Prevent accidental deletion of db1 " `
-ResourceGroupName " RG1 " `
-ResourceName " sql60152867/db1 " `
-ResourceType " Microsoft.Sql/servers/databases "
Replace RG1 and sql60152867 with the actual resource group and SQL logical server that hosts db1.
Azure CLI Method
Use Azure CLI only if the lab gives Cloud Shell and you know the full resource ID.
First get the database resource ID:
az sql db show \
--resource-group < resource-group-name > \
--server < sql-server-name > \
--name db1 \
--query id \
--output tsv
Then create the lock:
az resource lock create \
--name PreventDelete-db1 \
--lock-type CanNotDelete \
--resource < database-resource-id > \
--notes " Prevent accidental deletion of db1 "
Azure CLI supports resource-level lock creation with --lock-type CanNotDelete or ReadOnly.
SSMS / T-SQL Clarification
SSMS is not the correct tool for this task.
A delete lock is an Azure Resource Manager control-plane setting, not a SQL data-plane setting. SQL Server Management Studio can manage database objects and run T-SQL, but it cannot create Azure portal deletion protection locks for an Azure SQL Database.
Submit