Configuring Database Auditing
This lesson explains auditing levels and destinations, and how Azure SQL Database differs from Azure SQL Managed Instance.
Learning outcomes
After completing this lesson, you will be able to:
- Describe what auditing records.
- Compare server-level and database-level policies.
- Choose an audit destination.
- Explain how Managed Instance auditing differs.
What auditing records
Azure SQL auditing tracks database events, and writes them to an audit log. It records logins, queries, schema changes and permission changes. It supports three goals: compliance evidence, understanding of ongoing activity, and investigation of suspected misuse. An audit trail also has a preventive value, since people know that their actions are recorded.
The default policy captures successful and failed logins and completed batches, through the action groups BATCH_COMPLETED_GROUP, SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP and FAILED_DATABASE_AUTHENTICATION_GROUP. The statement text in a record is limited to 4,000 characters, and anything beyond that is truncated. Temporary tables and tempdb are not audited, and databases with a question mark in their names are not supported.
Default audit coverage
Server-level and database-level auditing
Azure SQL Database auditing can be set at two levels. A server policy applies to all databases on the logical server, existing and future. A database policy applies to a single database. If both are on, both operate side by side, and events are recorded twice: enabling both does not override anything. Microsoft recommends the server policy in most cases. A database policy is suitable if one database has a different destination or different action groups.
If the requirement is to ensure that every database, including new ones, is audited, then use the server policy.
The following diagram shows the scope of a server auditing policy.

Destinations
The logs can go to three destinations, and a policy can write to more than one. The following table shows how to choose.
| Destination | Format and access | Best for |
|---|---|---|
| Azure Storage account | .xel files in append blobs, in a container named sqldbauditlogs | Long-term, low-cost retention |
| Log Analytics workspace | The AzureDiagnostics table or resource-specific tables, queried with KQL | Analysis and Microsoft Sentinel |
| Event Hubs | A stream of events | Sending to a third-party SIEM |
If logs go to a storage account behind a firewall, the server needs a managed identity with the Storage Blob Data Contributor role, and the account must allow trusted services. Immutable storage can protect audit logs from tampering. A retention period can be set on the storage destination. In Log Analytics, table retention applies instead.
Choosing an audit destination
Enabling auditing
In the Azure portal, open the logical server, choose Auditing under Security, turn it on, and select destinations. The same can be done with the following command, which sends the server's audit logs to a workspace.
az sql server audit-policy update --resource-group RG --name SERVER --state Enabled \
--lat-workspace-id WORKSPACE_RESOURCE_ID --log-analytics-target-state EnabledMicrosoft Support operations auditing is a separate option that records actions by Microsoft engineers on the server during a support case, which matters for strict compliance needs. Azure Policy has a built-in definition that audits or deploys SQL auditing.
Azure SQL Managed Instance
Azure SQL Managed Instance behaves differently, as it is closer to SQL Server. Auditing is configured with T-SQL: a CREATE SERVER AUDIT statement names a destination, and a CREATE SERVER AUDIT SPECIFICATION or database specification states what to record. The destination is either a URL for a blob container, or EXTERNAL_MONITOR, which sends events through a diagnostic setting to a workspace or Event Hubs.
CREATE SERVER AUDIT [InstanceAudit] TO EXTERNAL_MONITOR;
CREATE SERVER AUDIT SPECIFICATION [LoginAudit] FOR SERVER AUDIT [InstanceAudit]
ADD (FAILED_LOGIN_GROUP), ADD (SUCCESSFUL_LOGIN_GROUP) WITH (STATE = ON);
ALTER SERVER AUDIT [InstanceAudit] WITH (STATE = ON);Candidates should remember this difference: the portal page drives auditing on Azure SQL Database, whereas T-SQL drives it on Managed Instance.
Auditing differences
Using audit data
Audit logs are valuable only if someone examines them. With Log Analytics as a destination, KQL can find failed logins or unusual statements. Microsoft Sentinel has a solution for Azure SQL, with analytics rules that detect suspicious activity. Note a limit: failed Microsoft Entra logins do not appear in the SQL audit log, because the failure occurs before the connection reaches the database. Look for them in Microsoft Entra sign-in logs. Audit logs may include sensitive data within statement text, so restrict access to the destination.
Meeting an audit requirement
A company with 30 Azure SQL databases must keep audit data for seven years at low cost, and security analysts must be able to query the last 90 days in Microsoft Sentinel. New databases must be included automatically. What should you configure?
Use a server-level audit policy on each logical server, so that new databases are included, with two destinations: a storage account, with a lifecycle policy and immutability for seven years, and a Log Analytics workspace on which Microsoft Sentinel is enabled.
Database-level policies would miss new databases. Event Hubs is a streaming route rather than a retention store. Keeping seven years in the analytics tier of a workspace would meet the requirement, but not at low cost.
A server audit policy and a database audit policy are both on. What happens?
Show answer
Both operate, so events are recorded twice. Neither overrides the other.
Exam Tips
Remember for the exam
- A server policy covers all databases, including new ones.
- Server and database policies run side by side, without overriding each other.
- Managed Instance auditing is configured with T-SQL.
- Failed Entra logins appear in Entra sign-in logs.