Lesson 3 of 3 Permissions, Authentication and Auditing

Auditing Azure SQL and SQL Server

This lesson explains Azure SQL auditing levels and destinations, SQL Server Audit specifications and how to plan auditing.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish between server-level and database-level Azure SQL auditing.
  • Choose an audit destination for a requirement.
  • Describe server audits and audit specifications in SQL Server.

Azure SQL auditing

Azure SQL auditing is enabled in the portal, CLI or templates at the server level, which audits every database on the logical server, or at the database level. When both are enabled, both audits run; a database-level audit does not override the server audit. Audit logs go to one or more destinations, compared in the following table.

DestinationBest for
Azure Storage accountLow-cost, long-term retention; read with sys.fn_get_audit_file or the portal
Log Analytics workspaceKQL queries, workbooks, alerts and Microsoft Sentinel
Event HubsStreaming to a SIEM or third-party tool

The default action groups capture successful and failed database authentications and completed batches (BATCH_COMPLETED_GROUP), which records the T-SQL statements run. Other groups can be added with PowerShell or the REST API, such as permission and schema changes. Auditing of Microsoft support operations records actions by Microsoft engineers during support cases. Ledger tables complement auditing by proving that the data itself was not altered.

Match the pairs

Audit destinations

Exam skills 2.1.6

Match each auditing need with the destination that fits it.

Log in to try this activity Interactive activities are free with an account.

SQL Server Audit

On SQL Server and Azure SQL Managed Instance, a server audit defines the target (a file, the Windows Security log or Application log, or a URL on Managed Instance), and server audit specifications and database audit specifications choose what is recorded: action groups such as FAILED_LOGIN_GROUP, or individual actions on objects for specific principals.

CREATE SERVER AUDIT PayrollAudit TO FILE (FILEPATH = 'D:\Audit\');
ALTER SERVER AUDIT PayrollAudit WITH (STATE = ON);

USE HR;
CREATE DATABASE AUDIT SPECIFICATION PayrollReads
FOR SERVER AUDIT PayrollAudit
    ADD (SELECT, UPDATE ON OBJECT::HR.Salary BY public)
WITH (STATE = ON);

SELECT event_time, server_principal_name, statement
FROM sys.fn_get_audit_file('D:\Audit\*.sqlaudit', DEFAULT, DEFAULT);
Match the pairs

SQL Server Audit objects

Exam skills 2.1.6

Match each SQL Server Audit object with its role.

Log in to try this activity Interactive activities are free with an account.

Planning auditing

Audit design starts from the questions it must answer, such as who read salary data or who changed permissions, and the retention that regulations require. Auditing every batch on a busy database produces large volumes, which cost storage and ingestion, so focused action groups or object-specific actions reduce noise. Audit destinations must be protected from the people being audited, for example with immutable storage or a workspace that database administrators cannot modify.

Select all that apply

Planning an audit

Exam skills 2.1.6

Identify the good practices for planning auditing.

Log in to try this activity Interactive activities are free with an account.
Worked example

Auditing all databases on a server

A logical server hosts 40 databases, and new databases are added monthly. The security team wants all authentication events and statements from every database in a Log Analytics workspace, including databases created later, with minimal effort. What should the developer configure?

Enable server-level auditing with the Log Analytics workspace as the destination. Server-level auditing applies to every existing and future database on the server with the default action groups that capture authentication and batches. Database-level auditing would need configuring for each new database, and a storage account destination does not support KQL queries directly.

Check yourself

If server-level and database-level auditing are both enabled, which runs?

Show answer

Both; the database audit does not replace the server audit.

Exam Tips

Remember for the exam

  • Audit every database, including future ones: server-level auditing.
  • KQL queries and alerts on audit data: Log Analytics destination.
  • Cheap long-term retention: storage account; SIEM streaming: Event Hubs.
  • Server and database audits both run when both are enabled.