Tag: Database Auditing

Implement auditing – Part 3 (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Secure, optimize, and deploy database solutions (35–40%)
   --> Implement data security and compliance
      --> Implement auditing


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

In Parts 1 and 2, you learned how SQL Server auditing works, how Azure SQL auditing integrates with Azure services, and how auditing supports compliance, monitoring, and forensic investigations. This final section summarizes the topic, compares auditing with related security features, presents real-world scenarios, and concludes with 10 DP-800-style practice exam questions.


Auditing vs. Other SQL Security Features

Understanding the differences between SQL Server security features is critical for the DP-800 exam.

FeaturePurposeProtects Data?Records Activity?
SQL Server AuditRecords security eventsNoYes
Dynamic Data MaskingObscures sensitive dataYesNo
Row-Level SecurityRestricts row accessYesNo
Always EncryptedEncrypts sensitive columnsYesNo
Transparent Data Encryption (TDE)Encrypts database filesYesNo
SQL Server PermissionsControls accessYesNo
Microsoft Defender for SQLDetects suspicious activityIndirectlyPartially

A common exam question is determining which technology satisfies a particular requirement:

  • Need to record who accessed payroll data? → Auditing
  • Need to hide Social Security numbers? → Dynamic Data Masking
  • Need to encrypt credit card numbers? → Always Encrypted
  • Need users to see only their own records? → Row-Level Security
  • Need protection for database files at rest? → Transparent Data Encryption

SQL Server Audit Workflow

A simplified auditing workflow is shown below.

User Action
SQL Server
Audit Specification
(Server or Database)
SQL Server Audit
Audit Target
(File, Azure Storage,
Log Analytics, Event Hub)
Investigation /
Compliance Reporting

Common Audited Events

Organizations commonly audit:

Authentication

  • Successful logins
  • Failed logins
  • Password changes
  • Login creation
  • Login deletion

Administrative Changes

  • CREATE DATABASE
  • DROP DATABASE
  • ALTER DATABASE
  • CREATE LOGIN
  • ALTER LOGIN
  • Server role changes

Security Changes

  • GRANT
  • DENY
  • REVOKE
  • Permission changes
  • Role membership changes

Data Access

  • SELECT
  • INSERT
  • UPDATE
  • DELETE
  • EXECUTE

Typically, organizations only audit access to sensitive tables rather than every table in the database.


Schema Changes

  • CREATE TABLE
  • ALTER TABLE
  • DROP TABLE
  • CREATE PROCEDURE
  • ALTER PROCEDURE
  • CREATE VIEW

Real-World Scenario 1

A healthcare provider stores patient records in Azure SQL Database.

Requirements:

  • Record every UPDATE made to patient records.
  • Retain logs for seven years.
  • Alert security personnel when permission changes occur.

Recommended solution:

  • Enable Azure SQL Auditing.
  • Send logs to Azure Storage for long-term retention.
  • Send logs to Log Analytics.
  • Configure Azure Monitor alerts.
  • Forward events to Microsoft Sentinel.

Real-World Scenario 2

A financial institution experiences unauthorized data modifications.

Requirements:

  • Determine who modified account balances.
  • Determine when modifications occurred.
  • Review executed SQL statements.

Solution:

Query audit logs using:

  • sys.fn_get_audit_file() (SQL Server)
  • Log Analytics (Azure SQL)
  • Azure Storage audit files

Review:

  • Login name
  • Timestamp
  • Statement
  • Database
  • Object
  • Session ID

Real-World Scenario 3

A company wants to monitor privileged users only.

Instead of auditing every database action:

Audit:

  • Login events
  • Role changes
  • Permission changes
  • ALTER statements
  • DROP statements

This minimizes performance impact while providing meaningful security visibility.


Compliance Mapping

RequirementSQL Auditing Helps?
Determine who accessed sensitive dataYes
Record failed loginsYes
Detect unauthorized permission changesYes
Track schema modificationsYes
Recover deleted dataNo
Encrypt stored dataNo
Prevent unauthorized accessNo (permissions control access)

Remember:

Auditing provides evidence, not protection.


Performance Best Practices

For production environments:

✔ Audit only important events.

✔ Avoid auditing every SELECT statement unless required.

✔ Archive logs regularly.

✔ Protect audit files with appropriate permissions.

✔ Monitor storage consumption.

✔ Review audit logs routinely.

✔ Test audit configurations before production deployment.

✔ Separate audit storage from transaction log storage whenever practical.


DP-800 Exam Tips

Be comfortable answering questions about:

  • Server Audit vs. Database Audit Specification
  • Azure SQL auditing
  • Audit destinations
  • Log Analytics
  • Azure Storage
  • Event Hubs
  • Microsoft Sentinel
  • Azure Monitor
  • Compliance scenarios
  • Investigating suspicious activity
  • Performance implications of auditing

Quick Review

Remember these key concepts:

TopicKey Point
SQL Server AuditDefines where audit data is stored
Server Audit SpecificationAudits server-level events
Database Audit SpecificationAudits database-level events
Azure StorageLong-term audit storage
Log AnalyticsSearch and analyze audit events
Event HubsStream audit events
Azure MonitorAlerting and dashboards
Microsoft SentinelSIEM and threat investigation
Defender for SQLThreat detection
sys.fn_get_audit_file()Reads SQL Server audit files

Common DP-800 Pitfalls

Avoid these misconceptions:

  • Auditing does not encrypt data.
  • Auditing does not prevent unauthorized access.
  • Auditing is not a replacement for backups.
  • Auditing does not replace Microsoft Defender for SQL.
  • Dynamic Data Masking does not record access.
  • Always Encrypted does not log who viewed data.

Practice Exam Questions

Question 1

A company must determine who modified salary information in the Employees table. Which SQL Server feature should be implemented?

A. Transparent Data Encryption

B. SQL Server Audit

C. Dynamic Data Masking

D. Row-Level Security

Answer: B

Explanation:

SQL Server Audit records database activity, including UPDATE operations, allowing administrators to identify who modified data, when the modification occurred, and which statement was executed. The other options protect or restrict data but do not record user activity.


Question 2

Which SQL Server object specifies where audit records are written?

A. Database Audit Specification

B. Server Audit Specification

C. SQL Server Audit

D. Audit Action Group

Answer: C

Explanation:

The SQL Server Audit object defines the audit destination, such as a file, Windows Security Log, or Windows Application Log. Audit specifications determine which events are captured.


Question 3

An organization wants to search audit logs using Kusto Query Language (KQL). Which Azure service should store the audit data?

A. Azure Storage

B. Event Hubs

C. Log Analytics Workspace

D. Azure Key Vault

Answer: C

Explanation:

Log Analytics stores audit data in a format that supports KQL queries, dashboards, alerts, and Azure Monitor integration. Azure Storage is intended for long-term retention rather than interactive querying.


Question 4

Which audit specification captures database-level activities such as SELECT, UPDATE, and DELETE?

A. Server Audit

B. Database Audit Specification

C. Audit Target

D. Server Audit Specification

Answer: B

Explanation:

Database Audit Specifications capture actions performed within a database, including DML operations and permission changes. Server Audit Specifications capture server-level activities.


Question 5

Which Azure service is primarily intended for streaming audit events to external monitoring systems in near real time?

A. Azure Storage

B. Azure Files

C. Log Analytics

D. Azure Event Hubs

Answer: D

Explanation:

Azure Event Hubs provides scalable event streaming for integration with SIEM platforms, custom monitoring solutions, and security tools. It is optimized for real-time event ingestion.


Question 6

Which function is commonly used to read SQL Server audit files?

A. OPENROWSET()

B. sys.fn_get_audit_file()

C. sp_readaudit

D. sys.fn_audit_log()

Answer: B

Explanation:

sys.fn_get_audit_file() is the built-in table-valued function used to read SQL Server audit files and return audit events in a queryable format.


Question 7

A security administrator needs immediate notification whenever database permissions change. Which solution best meets this requirement?

A. Configure auditing with Log Analytics and Azure Monitor alerts.

B. Disable auditing and use transaction logs.

C. Store audit files only in Azure Storage.

D. Enable Transparent Data Encryption.

Answer: A

Explanation:

Auditing records permission changes, while Azure Monitor can generate alerts based on those audit events stored in Log Analytics. Azure Storage alone does not provide real-time alerting.


Question 8

Which statement correctly describes SQL Server auditing?

A. It encrypts sensitive columns.

B. It prevents unauthorized access to data.

C. It automatically restores deleted records.

D. It records security-related database and server activity.

Answer: D

Explanation:

Auditing records activities for monitoring, compliance, and investigation. It does not encrypt data, restore deleted records, or enforce permissions.


Question 9

Which audit target is generally recommended by Microsoft for most on-premises production SQL Server environments?

A. File

B. Windows Security Log

C. Windows Application Log

D. Azure Event Hubs

Answer: A

Explanation:

File targets provide excellent performance, scalability, and flexibility. They are the recommended destination for most production SQL Server deployments.


Question 10

Which Microsoft security service uses audit information to help detect suspicious database activity and investigate incidents?

A. Azure Backup

B. Microsoft Sentinel

C. SQL Server Agent

D. Azure Resource Manager

Answer: B

Explanation:

Microsoft Sentinel consumes audit logs from services such as Azure SQL Database to correlate events, detect threats, automate investigations, and assist security analysts. It complements auditing by providing advanced security analytics rather than simply recording events.


Final DP-800 Takeaways

For the DP-800 exam, remember these core principles:

  • SQL Server Audit defines where audit records are stored.
  • Server Audit Specifications capture server-level activities such as logins and server role changes.
  • Database Audit Specifications capture database-level activities such as data access and schema changes.
  • Azure Storage is ideal for long-term retention.
  • Log Analytics enables interactive querying, dashboards, and Azure Monitor alerts.
  • Azure Event Hubs supports real-time streaming to external systems.
  • Microsoft Sentinel extends auditing with SIEM capabilities, threat detection, and incident response.
  • Auditing provides accountability, supports compliance, and enables forensic investigations, but it does not replace encryption, access control, or threat protection technologies.

Go to the DP-800 Exam Prep Hub main page

Implement auditing – Part 2 (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Secure, optimize, and deploy database solutions (35–40%)
   --> Implement data security and compliance
      --> Implement auditing


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

Introduction

In Part 1, you learned about the SQL Server Audit architecture, audit specifications, audit targets, audit action groups, and how to configure and manage audits in SQL Server. In this section, we’ll examine how auditing works in Azure SQL services, how audit data integrates with Azure monitoring solutions, and the performance and operational considerations that are especially relevant for the DP-800 exam.


Auditing in Azure SQL Database

Azure SQL Database includes built-in auditing capabilities that are designed for cloud-native environments. Unlike on-premises SQL Server, Azure SQL Database can automatically integrate with Azure services for centralized monitoring and compliance.

Azure SQL auditing records database events such as:

  • Successful and failed logins
  • Database schema changes
  • Permission modifications
  • Data access (SELECT)
  • Data modifications (INSERT, UPDATE, DELETE)
  • Stored procedure execution
  • Security configuration changes
  • Administrative operations

Auditing can be configured at two levels:

  • Server level
  • Individual database level

Server-level auditing provides a consistent policy across all databases on the logical SQL server, while database-level auditing allows different auditing configurations for specific databases.


Azure SQL Auditing Architecture

Azure SQL Database
SQL Auditing
┌──────┼────────┐
▼ ▼ ▼
Storage Log Analytics Event Hub
Account Workspace

One audit configuration can send events to one or more Azure services.


Audit Destinations in Azure

Unlike SQL Server, Azure SQL Database supports several cloud-based audit destinations.

Azure Storage Account

The most common destination.

Benefits include:

  • Low-cost storage
  • Long-term retention
  • Backup
  • Archive capabilities
  • Easy export
  • Compliance support

Organizations frequently retain audit logs in Storage Accounts for multiple years.


Log Analytics Workspace

Many organizations choose Log Analytics because it supports:

  • Interactive searches
  • Kusto Query Language (KQL)
  • Dashboards
  • Alerting
  • Workbooks
  • Azure Monitor integration

Example investigations include:

  • Failed login trends
  • Privileged user activity
  • Permission changes
  • Suspicious DELETE operations

Azure Event Hubs

Event Hubs allows organizations to stream audit events in near real time.

Typical integrations include:

  • SIEM platforms
  • Security monitoring solutions
  • Custom monitoring applications
  • Third-party security tools

Configuring Azure SQL Auditing

Auditing can be enabled through:

  • Azure Portal
  • Azure CLI
  • PowerShell
  • ARM templates
  • Bicep
  • Terraform
  • Azure REST API

Within the Azure Portal, the configuration typically involves:

  1. Select the SQL Server or database.
  2. Open Auditing under the Security section.
  3. Enable auditing.
  4. Choose one or more destinations.
  5. Configure retention settings.
  6. Save the configuration.

Retention Policies

Azure Storage destinations support configurable retention periods.

Examples include:

  • 90 days
  • 180 days
  • 1 year
  • Multiple years

Retention should match organizational compliance requirements.

Examples:

RegulationTypical Retention
PCI DSSAt least one year
HIPAASeveral years (organization-specific)
SOXOften seven years
Internal security policiesVaries

Azure SQL Managed Instance Auditing

Azure SQL Managed Instance supports auditing capabilities similar to SQL Server while integrating with Azure services.

Supported destinations include:

  • Azure Storage
  • Log Analytics
  • Event Hubs

Managed Instance also supports many SQL Server auditing features, making it easier to migrate on-premises workloads to Azure without redesigning security monitoring.


Microsoft Fabric SQL Auditing Considerations

Microsoft Fabric SQL databases and SQL analytics endpoints are integrated into the broader Microsoft Fabric governance ecosystem.

Rather than relying solely on traditional SQL Server Audit objects, Fabric environments also benefit from:

  • Microsoft Purview governance
  • Activity monitoring
  • Workspace monitoring
  • Capacity monitoring
  • Microsoft Fabric Activity Log
  • Azure Monitor integration
  • Microsoft Defender integration

For the DP-800 exam, understand that auditing in Fabric emphasizes cloud-native monitoring and governance rather than traditional SQL Server Audit files.


Viewing Audit Logs

Azure Portal

Administrators can review:

  • Audit status
  • Destination
  • Retention
  • Recent activity

The portal provides quick access to Log Analytics and Storage Accounts where audit records reside.


Log Analytics

Audit records become searchable using Kusto Query Language (KQL).

Example:

AzureDiagnostics
| where Category == "SQLSecurityAuditEvents"
| where statement_s contains "DELETE"

This query returns DELETE statements captured by SQL auditing.


Storage Account

Audit files stored in Azure Storage can be:

  • Downloaded
  • Archived
  • Imported
  • Processed by external tools
  • Loaded into Power BI
  • Queried with Azure Data Explorer

Integrating Auditing with Azure Monitor

Azure Monitor provides centralized monitoring across Azure resources.

Audit logs can generate:

  • Alerts
  • Dashboards
  • Metrics
  • Workbooks
  • Notifications

Example alert:

Notify the security team whenever more than ten failed login attempts occur within five minutes.


Microsoft Sentinel Integration

Microsoft Sentinel is Microsoft’s cloud-native Security Information and Event Management (SIEM) platform.

Audit logs can be streamed into Sentinel where security analysts can:

  • Detect attacks
  • Investigate incidents
  • Correlate events
  • Create analytics rules
  • Build hunting queries
  • Automate responses

Example scenario:

  1. Repeated failed logins
  2. Successful privileged login
  3. Mass DELETE operations

Sentinel correlates these events into a potential security incident.


Microsoft Defender for SQL

Auditing and Microsoft Defender for SQL complement one another.

AuditingDefender for SQL
Records activityDetects threats
Supports complianceUses behavioral analytics
Captures eventsGenerates security alerts
Used during investigationsIdentifies suspicious behavior

For example:

Auditing records that a user executed a large number of DELETE statements, while Defender for SQL may identify that behavior as anomalous and raise a security alert.


Performance Considerations

Auditing introduces some performance overhead because every audited event must be written to an audit target.

The impact depends on factors such as:

  • Number of audited events
  • Frequency of activity
  • Storage performance
  • Audit destination
  • Network latency (Azure)

Fortunately, SQL Server auditing is highly optimized and generally has minimal impact when configured appropriately.


Reducing Performance Overhead

Microsoft recommends several strategies.

Audit Only Necessary Events

Avoid auditing every possible action.

Instead, focus on:

  • Logins
  • Permission changes
  • Sensitive table access
  • Administrative operations

Avoid Excessive SELECT Auditing

High-volume transactional systems may execute millions of SELECT statements daily.

Auditing every SELECT can:

  • Increase storage consumption
  • Generate enormous audit files
  • Reduce performance

Instead, audit only access to sensitive tables.


Separate Audit Storage

Whenever possible:

  • Store audit files on separate disks.
  • Use dedicated Azure Storage Accounts.
  • Avoid sharing storage with transaction logs.

Archive Older Logs

Large audit repositories become difficult to search.

Implement:

  • Automatic archiving
  • Lifecycle management
  • Long-term storage
  • Periodic cleanup

Monitoring Audit Health

Administrators should routinely verify that auditing is functioning correctly.

Check:

  • Audit status
  • Storage availability
  • Remaining storage capacity
  • Failed audit writes
  • Log Analytics ingestion
  • Event Hub connectivity
  • Audit retention settings

Monitoring helps prevent gaps in audit coverage.


Common Auditing Scenarios

Scenario 1

A hospital must record every update to patient records.

Recommended approach:

  • Database auditing
  • Audit UPDATE operations
  • Store logs in Azure Storage
  • Retain logs according to healthcare regulations

Scenario 2

A bank wants immediate notification when administrators change permissions.

Recommended approach:

  • Audit permission changes
  • Send events to Log Analytics
  • Create Azure Monitor alerts
  • Forward alerts to Microsoft Sentinel

Scenario 3

A company wants to investigate suspicious DELETE statements after a potential insider attack.

Recommended approach:

  • Query audit logs
  • Identify user accounts
  • Review timestamps
  • Correlate activity with authentication logs

Common Mistakes

Candidates often confuse several related security technologies.

FeaturePurpose
AuditingRecords activity
Dynamic Data MaskingHides data
Row-Level SecurityFilters rows
Always EncryptedEncrypts data
Transparent Data EncryptionEncrypts database files
Microsoft Defender for SQLDetects threats

Remember:

  • Auditing records activity.
  • It does not prevent activity.
  • It does not encrypt data.
  • It does not mask data.

DP-800 Exam Tips

Expect scenario-based questions such as:

  • Which audit destination should be selected?
  • Which service enables security investigations?
  • Which Azure service should receive audit logs?
  • How should audits be configured for compliance?
  • Which audit events should be enabled?
  • How can auditing be integrated with Azure Monitor?

Also remember:

  • Azure Storage is commonly used for long-term retention.
  • Log Analytics is best for querying and analysis.
  • Event Hubs is designed for real-time event streaming.
  • Microsoft Sentinel builds on audit logs to provide advanced threat detection and incident response.
  • Microsoft Defender for SQL complements auditing by detecting suspicious behavior rather than simply recording it.

Best Practices Summary

  • Enable auditing for all production databases.
  • Audit only security-relevant events to minimize overhead.
  • Prefer centralized monitoring using Azure Monitor and Log Analytics.
  • Protect audit logs from unauthorized modification or deletion.
  • Configure retention policies that satisfy organizational and regulatory requirements.
  • Integrate auditing with Microsoft Sentinel for security operations.
  • Periodically review audit logs and validate that auditing remains enabled after deployments or configuration changes.
  • Document audit policies and test recovery procedures for audit data.

Go to the DP-800 Exam Prep Hub main page

Implement auditing – Part 1 (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Secure, optimize, and deploy database solutions (35–40%)
   --> Implement data security and compliance
      --> Implement auditing


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

Introduction

Auditing is a critical security and compliance capability in Microsoft SQL Server, Azure SQL Database, Azure SQL Managed Instance, and Microsoft Fabric SQL databases. An audit records database and server activities so administrators can determine who performed an action, when it occurred, what object was affected, and whether the action succeeded or failed.

Auditing plays an important role in:

  • Security monitoring
  • Regulatory compliance
  • Incident investigations
  • Forensics
  • Insider threat detection
  • Change tracking
  • Governance

For the DP-800 exam, you should understand:

  • SQL Server Audit architecture
  • Server and database audit specifications
  • Audit targets
  • Audited action groups
  • Creating and managing audits
  • Azure SQL auditing
  • Performance considerations
  • Best practices

Why Database Auditing Matters

Unlike backups or transaction logs, auditing focuses on security events rather than data recovery.

Auditing helps answer questions such as:

  • Who deleted a customer record?
  • Who changed employee salaries?
  • Who attempted unauthorized access?
  • Which administrator modified security settings?
  • When was sensitive information viewed?
  • Which login repeatedly failed?

Organizations frequently require auditing for compliance standards including:

  • HIPAA
  • PCI DSS
  • SOX
  • GDPR
  • ISO 27001
  • FedRAMP

SQL Server Audit Architecture

SQL Server auditing is built using three major components.

SQL Server Audit
Audit Target
(File, Windows Security Log,
Windows Application Log)
Audit Specification
(Server or Database)
Audited Actions

The architecture is intentionally modular.


Component 1 — SQL Server Audit

The Audit object defines:

  • Where audit information is written
  • How failures are handled
  • File size
  • Retention behavior
  • Queue delay
  • Whether auditing is enabled

Think of the Audit object as the destination.

Example:

CREATE SERVER AUDIT SecurityAudit
TO FILE
(
FILEPATH = 'D:\AuditLogs\'
);
GO
ALTER SERVER AUDIT SecurityAudit
WITH (STATE = ON);

The audit itself records nothing until specifications are attached.


Component 2 — Audit Specifications

Audit specifications determine what activities should be captured.

Two specification types exist.

Server Audit Specification

Captures server-level events.

Examples include:

  • Login creation
  • Login failures
  • ALTER LOGIN
  • Server role changes
  • Backup operations
  • Database creation
  • Database deletion

Example:

CREATE SERVER AUDIT SPECIFICATION ServerAuditSpec
FOR SERVER AUDIT SecurityAudit
ADD (FAILED_LOGIN_GROUP),
ADD (SERVER_ROLE_MEMBER_CHANGE_GROUP);
ALTER SERVER AUDIT SPECIFICATION ServerAuditSpec
WITH (STATE = ON);

Database Audit Specification

Captures activity inside a database.

Examples:

  • SELECT
  • INSERT
  • UPDATE
  • DELETE
  • EXECUTE
  • Permission changes
  • Schema changes

Example:

USE SalesDB;
CREATE DATABASE AUDIT SPECIFICATION DatabaseAuditSpec
FOR SERVER AUDIT SecurityAudit
ADD (SELECT ON dbo.Customers BY PUBLIC),
ADD (UPDATE ON dbo.Customers BY PUBLIC);
ALTER DATABASE AUDIT SPECIFICATION DatabaseAuditSpec
WITH (STATE =ON);

Relationship Between Audit Objects

SQL Server Audit
├──────────────┐
│ │
▼ ▼
Server Audit Database Audit
Specification Specification
│ │
▼ ▼
Audited Actions Database Actions
Audit Log

One audit may support multiple specifications.


Audit Targets

The audit target specifies where audit events are stored.

SQL Server supports three primary targets.

1. File Target

Most common.

Advantages:

  • High performance
  • Large storage capacity
  • Easy backup
  • Easy archive
  • Supports filtering
  • Recommended by Microsoft

Example

TO FILE
(
FILEPATH='D:\AuditLogs\'
)

2. Windows Security Log

Suitable when:

  • Centralized Windows auditing exists
  • Security teams monitor Security logs
  • Compliance requires OS-level auditing

Advantages

  • Tamper resistant
  • Centrally managed

Requires elevated permissions.


3. Windows Application Log

Less secure than the Security Log.

Typically used when:

  • Security Log permissions are unavailable
  • Simpler deployments
  • Testing environments

Audit Actions

SQL Server audits individual actions or groups of actions.

Examples include:

  • SELECT
  • INSERT
  • UPDATE
  • DELETE
  • EXECUTE
  • CREATE TABLE
  • ALTER TABLE
  • DROP TABLE
  • LOGIN
  • LOGOUT

Audit Action Groups

Rather than auditing individual commands, SQL Server commonly audits predefined action groups.

Examples include:

Action GroupDescription
FAILED_LOGIN_GROUPFailed logins
SUCCESSFUL_LOGIN_GROUPSuccessful logins
DATABASE_OBJECT_CHANGE_GROUPTable and view changes
DATABASE_PERMISSION_CHANGE_GROUPPermission modifications
SERVER_ROLE_MEMBER_CHANGE_GROUPChanges to server roles
SCHEMA_OBJECT_CHANGE_GROUPCREATE/ALTER/DROP objects
DATABASE_ROLE_MEMBER_CHANGE_GROUPChanges to database roles
BACKUP_RESTORE_GROUPBackup and restore events
SERVER_OBJECT_CHANGE_GROUPServer object modifications

These predefined groups simplify auditing and reduce administrative effort.


Creating a Basic Audit

Step 1

Create the audit.

CREATE SERVER AUDIT MyAudit
TO FILE
(
FILEPATH='D:\AuditLogs\'
);

Step 2

Enable the audit.

ALTER SERVER AUDIT MyAudit
WITH (STATE=ON);

Step 3

Create a database audit specification.

USE SalesDB;
CREATE DATABASE AUDIT SPECIFICATION SalesAudit
FOR SERVER AUDIT MyAudit
ADD
(
SELECT ON dbo.Customers BY PUBLIC
);

Step 4

Enable the specification.

ALTER DATABASE AUDIT SPECIFICATION SalesAudit
WITH (STATE=ON);

Now every SELECT against Customers is captured.


Viewing Audit Logs

Audit files can be queried using the built-in table-valued function:

SELECT *
FROM sys.fn_get_audit_file
(
'D:\AuditLogs\*',
DEFAULT,
DEFAULT
);

Returned information includes:

  • Event time
  • Login name
  • Database name
  • Server name
  • Object name
  • Statement executed
  • Action ID
  • Session ID
  • Success or failure

This function is commonly used for reporting and investigations.


Managing Audit State

Audits can be enabled or disabled without deleting them.

Disable:

ALTER SERVER AUDIT SecurityAudit
WITH (STATE = OFF);

Enable:

ALTER SERVER AUDIT SecurityAudit
WITH (STATE = ON);

Similarly, individual audit specifications can be enabled or disabled independently of the audit object.


Catalog Views for Auditing

Several system catalog views help administrators monitor audit configuration.

ViewPurpose
sys.server_auditsLists configured server audits
sys.server_audit_specificationsLists server audit specifications
sys.database_audit_specificationsLists database audit specifications
sys.server_audit_specification_detailsDisplays server audit actions
sys.database_audit_specification_detailsDisplays database audit actions
sys.dm_server_audit_statusShows audit runtime status

Example:

SELECT *
FROM sys.server_audits;

Audit Failure Behavior

SQL Server allows administrators to specify what happens if an audit target becomes unavailable.

Options include:

Continue

Database operations continue even if auditing fails.

Suitable for:

  • Development environments
  • Non-critical systems

Fail Operation

Only the audited operation fails.

Example:

  • A user attempts to update a table.
  • The audit cannot write to disk.
  • The UPDATE is rejected.

This option helps ensure sensitive operations are never performed without being audited.


Shut Down Server

The SQL Server instance shuts down if auditing fails.

This provides the highest level of security but can impact availability. It is generally reserved for environments with strict regulatory requirements.


Best Practices

Microsoft recommends the following auditing practices:

  • Audit only important security events to reduce overhead.
  • Prefer file targets for performance and scalability.
  • Protect audit files with appropriate NTFS permissions.
  • Archive audit logs regularly.
  • Monitor available disk space to prevent audit interruptions.
  • Test audit configurations before deploying to production.
  • Use separate storage volumes for audit files when possible.
  • Review audit logs regularly rather than collecting them without analysis.
  • Combine auditing with least-privilege security and Microsoft Defender for SQL for comprehensive protection.
  • Document audit policies to satisfy compliance requirements and facilitate incident response.

DP-800 Exam Tips

  • Understand the distinction between a SQL Server Audit (defines the destination) and an Audit Specification (defines what is captured).
  • Know when to use Server Audit Specifications versus Database Audit Specifications.
  • Be familiar with common audit action groups, especially login, permission, object change, and backup-related groups.
  • Remember that sys.fn_get_audit_file is the primary method for reading audit files.
  • Recognize that file targets are generally Microsoft’s recommended choice for production deployments because they offer the best balance of performance, scalability, and manageability.
  • Be able to identify scenarios where auditing supports regulatory compliance, forensic investigations, and security monitoring.

Go to the DP-800 Exam Prep Hub main page