Introduction
When performing a Point-in-Time Restore (PITR) of an Azure SQL Database, you may need the Database ID to correctly identify the source database, especially in automation or scripting scenarios. This guide outlines three methods to find the SQL Database ID using the Azure Portal, Azure CLI, and Azure PowerShell.
Prerequisites
- Ensure you or the service principal performing the action has
ReaderorContributoraccess to the resource group containing the database.
Procedure
This section provides three methods for retrieving the Azure SQL Database ID.
Method 1: Use the Azure Portal
- Sign in to the Azure Portal.
- Navigate to SQL databases.
- Select the target SQL database from the list.
- On the Overview page, locate the Essentials section and select JSON View.
- In the JSON view, find the
idfield. This value is the full Database Resource ID.
It will have the following format.
/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.Sql/servers/<server-name>/databases/<database-name>
Method 2: Use the Azure CLI
You can retrieve the database ID by running the az sql db show command.
$ az sql db show \ --name <database-name> \ --server <server-name> \ --resource-group <resource-group-name> \ --query "id" \ --output tsv
This command returns the full resource ID string of the database.
Method 3: Use Azure PowerShell
You can retrieve the database ID by running the Get-AzSqlDatabase command.
Get-AzSqlDatabase ` -ResourceGroupName "<resource-group-name>" ` -ServerName "<server-name>" ` -DatabaseName "<database-name>" | Select-Object Id
This command displays the Id property of the specified database.
Additional Information
- For more details on database recovery, refer to the official documentation on Azure SQL Database recovery using backups.