Implementing Auditing and Threat Detection. If you run a database without it, you’re flying blind. You won’t know who accessed sensitive data, whether someone tried to break in, or how a breach happened — until it’s too late. For the DP-300 exam, this is the difference between a secure database and a compliance nightmare.
Jump to a section
A simple way to picture Implementing Auditing and Threat Detection
A museum security guard does more than just stand at the entrance. They review footage from every corridor, check logs of who opened which display case, and monitor for anyone trying to tamper with an exhibit.
When a visitor tries to touch a painting, the guard doesn’t just shout — they record the time, the camera angle, and the person’s description, then lock down that wing if needed. This isn’t about being suspicious of every guest; it’s about having a detailed, unchangeable record of everything that happens, so if something goes missing, you know exactly who was where and when.
In the database world, you play that guard. Auditing is the CCTV system that records every query and login attempt, and threat detection is the alarm that sounds when someone tries to break into a restricted area. Without this, your database is a museum with no cameras — you only find out something’s stolen when it’s already gone.
Auditing means keeping a permanent, tamper-proof log of every action taken on a database. Think of it as a black box recorder for your data. When you enable auditing in Azure SQL Database or SQL Server, the database engine writes a record every time someone runs a query, changes a table, logs in, or fails to log in. This record includes the exact SQL command, the user’s account name, the time, and the source IP address.
Threat detection is a separate but related feature that scans those logs in real time. It looks for patterns that match known attack signatures: someone trying to brute-force a password (hundreds of failed logins in a minute), SQL injection attempts (special characters or malformed queries), or access from unusual locations (a login from a country where your company has no employees). When it finds a match, it raises an alert — often through Azure Defender for SQL, which can send an email, trigger an automated response, or integrate with security information and event management (SIEM) systems.
The central tool for this in Azure is the SQL auditing feature, which stores logs in an Azure Storage account, a Log Analytics workspace, or an Event Hub. You can choose to log server-level events (like login attempts) or database-level events (like SELECT, INSERT, UPDATE, DELETE). The logs are immutable — once written, they cannot be changed or deleted, even by a database administrator. This is crucial for compliance with regulations like GDPR, HIPAA, or SOC 2, which require you to prove who accessed what data and when.
Why does this matter? Without auditing, if a hacker steals customer credit card numbers, you have no way to trace how they got in. With auditing, you can replay the exact sequence of events. Threat detection adds a pro-active layer: it can stop an attack in progress by alerting you before the damage is done. For example, Azure Defender for SQL can identify anomalous access patterns, like a user who normally logs in from London suddenly connecting from a known malicious IP address in Eastern Europe.
The key components to understand are:
Azure SQL Auditing: Enables logging of database events, stores them in Azure Storage or Log Analytics.
Azure Defender for SQL: Provides threat detection, vulnerability assessment, and advanced security monitoring.
Log Analytics: A service that collects and queries log data from multiple sources, allowing you to search across all your audits.
Audit Specifications: Define which events to audit — server-level (like login failures) or database-level (like data changes).
Alert Rules: Configurable conditions in Azure that trigger notifications when a threat is detected.
When you set up auditing in the Azure portal, you typically start by going to your SQL server or database, selecting ‘Auditing’ under Security, and turning it on. You then choose a storage destination. The simplest option is to stream logs to an Azure Storage account, but for deeper analysis, you send them to a Log Analytics workspace. Once enabled, all audit records are automatically written. You can query them using Kusto Query Language (KQL) to find, say, all failed logins in the last 24 hours.
For threat detection, you enable Azure Defender for SQL on the server or database level. This activates a set of built-in detection rules. You don’t need to write those rules yourself — Microsoft updates them based on global threat intelligence. However, you can also create custom alert rules using Azure Monitor to match specific patterns relevant to your organisation.
Importantly, auditing and threat detection are not the same thing. Auditing is passive recording; threat detection is active monitoring. You need both for a complete security posture. The exam will test that you know when to use each, how to configure them, and what the default settings are — for example, that auditing is disabled by default, and that threat detection is an add-on feature that requires Azure Defender for SQL.
Enable SQL Auditing on the Server
Open the Azure portal, navigate to your SQL server, select 'Auditing' under Security, and toggle it to 'ON'. You must choose a storage destination — Azure Storage, Log Analytics, or Event Hub. This starts recording all server-level events like login attempts and role changes.
Configure Audit Log Destination and Retention
Once auditing is on, specify the Azure Storage account or Log Analytics workspace where logs will be sent. Set a retention period (e.g., 365 days) to meet compliance requirements. Without a retention setting, logs are kept indefinitely, which can be costly.
Enable Database-Level Auditing for Query Tracking
If you need to log specific queries (SELECT, INSERT, UPDATE, DELETE), go to the database itself, not just the server. Enable auditing at the database level and define which actions to capture. This is critical for compliance like HIPAA, where every data access must be tracked.
Enable Azure Defender for SQL
Navigate to the Azure Defender for SQL blade (under Security) on your SQL server or database. Turn it on — this activates threat detection and vulnerability assessment. You’ll start receiving alerts for suspicious activities like SQL injection or brute-force attacks.
Review and Customise Threat Detection Alerts
Check the default alert rules in Azure Defender for SQL. You can customise them to ignore safe IP ranges or create custom rules in Azure Monitor. For example, you might add a rule to alert if a specific user account logs in more than 10 times in one minute.
Run a Vulnerability Assessment Scan
In the Azure Defender for SQL blade, select 'Vulnerability Assessment' and run a scan. Review the findings — it will list missing patches, weak passwords, and overly permissive firewall rules. Remediate each issue (e.g., change a password, update a firewall rule) and rescan until all high-severity items are cleared.
An IT professional — let’s call her Priya — is the database administrator for a mid-sized healthcare company that handles patient records. The company must comply with HIPAA, which demands that every access to protected health information is logged and reviewable.
Priya’s first job is to enable auditing on all production SQL databases in Azure. She opens the Azure portal, navigates to each SQL server, clicks ‘Auditing’ under Security, and sets it to ‘ON’. She chooses to store the logs in a central Azure Storage account that is locked down with a long retention period — five years, as required by law. She also configures the audit to capture database-level events, because the business only cares about data modifications, not every login attempt.
A week later, a compliance officer asks: ‘Who accessed patient ID 4392 on 12 March?’ Priya runs a KQL query in Log Analytics: AzureDiagnostics | where TimeGenerated between (datetime(2025-03-12) .. datetime(2025-03-13)) and statement_s like ‘%4392%’. She instantly sees that user ‘jsmith’ ran a SELECT query at 2:15 PM from an IP address that belongs to the office network. She reports that it was a legitimate data analyst. Without auditing, she would have had no answer and risked a fine.
Separately, Priya enables Azure Defender for SQL. One afternoon, Azure Defender sends her an email alert: ‘Potential SQL injection attack detected on database ‘PatientsDB’ from IP 203.0.113.42’. She jumps into the portal, sees that the alert includes the time, the query that triggered it (a string with ‘OR 1=1’ — a classic SQL injection attempt), and a recommendation to review firewall rules. She checks the firewall and finds that a developer accidentally added a rule allowing access from a public IP. She removes it immediately. The attack was blocked before any data was exfiltrated.
Priya also uses vulnerability assessment, another feature of Azure Defender. On the first of every month, she runs a scan that reports missing patches, weak passwords, or misconfigured permissions. One scan reveals that a test database still uses the default admin password. She fixes it and writes a policy that all databases must pass vulnerability assessment before going into production.
In her monthly security review, she generates a report from Log Analytics that shows the top ten users by query volume and highlights any failed login attempts over 50 from a single IP. She presents this to the CISO, who uses it to justify additional security training for the team.
The concrete actions Priya takes as an IT professional are:
Enable SQL auditing on each server and database via the Azure portal or PowerShell.
Configure audit log destinations and retention periods to meet compliance requirements.
Enable Azure Defender for SQL and customise alert rules for your environment.
Review audit logs regularly using KQL queries in Log Analytics to investigate incidents.
Run vulnerability assessments and remediate findings before they become breaches.
The DP-300 exam tests your ability to configure and manage auditing and threat detection, not just define them. Expect scenario-based questions where you must choose the correct service or setting to meet a compliance or security requirement. The examiners love to test the differences between auditing at the server level versus the database level, and between storing logs in Azure Storage versus Log Analytics.
One common trap is a question that asks: ‘You need to ensure that all SELECT queries on a specific table are logged for compliance. What should you enable?’ Many beginners pick ‘server-level auditing’, but the correct answer is database-level auditing because server-level audit captures login events, not data modifications. Another trap: ‘You need to receive real-time alerts for SQL injection attempts. What feature should you use?’ The right answer is Azure Defender for SQL (threat detection), not just auditing, because auditing only records events — it doesn’t alert you.
Key exam topics to memorise:
Auditing is disabled by default. You must explicitly enable it.
Audit logs can be stored in Azure Storage (cheapest, long-term), Log Analytics (searchable via KQL), or Event Hub (for streaming to SIEM tools).
Azure Defender for SQL includes threat detection and vulnerability assessment. It is a paid add-on — not included with the base SQL database tier.
Threat detection alerts cover SQL injection, brute-force attacks, unusual access patterns (geographic anomalies), and access from known malicious IPs.
You can create custom alert rules in Azure Monitor to supplement the built-in patterns.
Vulnerability assessment runs on a schedule and provides a report with severity levels (high, medium, low) and remediation steps.
Audit records are immutable — once written, they cannot be modified or deleted by users, even DBAs.
You can enable auditing at the server level (captures logins and server actions) or database level (captures queries and data changes). You can also enable both.
Questions often present a compliance requirement like ‘A new regulation requires you to retain all database audit logs for seven years.’ The correct answer is to configure the retention period on the Azure Storage account where audit logs are stored, because the default retention is 0 (infinite).
Another pattern: ‘You need to detect when a user logs in from an unusual geographic location.’ The answer is to enable Azure Defender for SQL and ensure the threat detection policy includes ‘Anomalous geographic access’.
The exam also tests integration with other Azure services: for example, you can stream audit logs to Microsoft Sentinel (Azure’s SIEM) via Event Hubs for advanced threat hunting. Know that Log Analytics is the primary analysis endpoint, but Event Hubs are for streaming.
Finally, the exam may ask about performance impact. Auditing adds a small overhead to queries because writing logs takes resources. For high-throughput databases, you should monitor storage space and consider tiering to cheaper storage for older logs. Azure Defender for SQL scanning can also be resource-intensive; the exam recommends scheduling vulnerability assessments during off-peak hours.
Auditing is passive recording of database events; threat detection is active analysis that alerts you in real time.
Azure SQL auditing is disabled by default — you must explicitly enable it and choose a storage destination.
Audit logs are immutable and cannot be deleted or modified, even by a database administrator.
Azure Defender for SQL is a paid add-on that provides threat detection and vulnerability assessment.
Server-level auditing captures login events; database-level auditing captures queries and data changes — use both for full coverage.
Threat detection alerts include SQL injection, brute-force attacks, and anomalous geographic access, all based on built-in Microsoft threat intelligence.
To retain audit logs for years, configure the retention period on the Azure Storage account, not in the SQL database settings.
Vulnerability assessment should be scheduled during off-peak hours to minimise performance impact on production databases.
These come up on the exam all the time. Here's how to tell them apart.
Server-Level Auditing
Captures login successes, failures, and server role changes
Configured on the SQL server resource in Azure
Does not capture individual query statements like SELECT or INSERT
Database-Level Auditing
Captures all SQL queries (SELECT, INSERT, UPDATE, DELETE) on specific tables
Configured on each database resource individually
Provides granular data access tracking for compliance auditing
Azure SQL Auditing
Passive logging of events with no real-time alerts
Free with all Azure SQL tiers (when enabled)
Stores logs in Azure Storage / Log Analytics for later review
Azure Defender for SQL
Active monitoring that sends real-time alerts for suspicious activity
Paid add-on requiring Standard or Premium tier
Includes threat detection and vulnerability assessment scans
Log Analytics Workspace
Enables real-time querying of logs using Kusto Query Language
Best for short-term analysis and investigation
More expensive per gigabyte of data stored
Azure Storage Account for Logs
Stores logs as immutable .xel files, cheaper for long-term retention
Best for compliance archiving (years of data)
Cannot be queried directly; must download files to view
Threat Detection Alerts
Reactive — triggers when an attack is in progress or just occurred
Includes SQL injection, brute-force, and anomalous location alerts
Requires Azure Defender for SQL to be enabled
Vulnerability Assessment
Proactive — scans database configuration for weaknesses before an attack
Reports missing patches, weak passwords, and misconfigurations
Can be scheduled to run weekly or monthly
Mistake
Enabling auditing automatically alerts you to suspicious activity.
Correct
Auditing only logs events — it does not send alerts. You must enable Azure Defender for SQL (threat detection) to receive real-time notifications.
People confuse logging (recording) with monitoring (analysing and alerting). The word 'auditing' sounds like active oversight, but it’s purely passive.
Mistake
Threat detection is included by default in all Azure SQL database tiers.
Correct
Threat detection requires Azure Defender for SQL, which is a paid add-on. Basic and Standard tiers do not include it.
Microsoft bundles security features differently per tier. Beginners assume all security features are on by default because the platform touts 'security built-in'.
Mistake
Once audit logs are written to Azure Storage, an administrator can delete them to hide evidence.
Correct
Audit logs are immutable — once stored, they cannot be modified or deleted by any user, including administrators. This is enforced at the storage level.
In many on-premises systems, DBAs have full control over log files. Azure enforces immutability to meet compliance standards, which surprises people with on-prem experience.
Mistake
Server-level auditing and database-level auditing capture the same events.
Correct
Server-level auditing captures server-wide actions like login successes and failures, while database-level auditing captures queries and data changes on specific tables. They are complementary, not identical.
The names are misleading — 'server-level' sounds broader, but it actually covers a different set of events than 'database-level'. Beginners mix them up.
Mistake
Vulnerability assessment and threat detection are the same feature.
Correct
Vulnerability assessment scans for misconfigurations and missing patches on a schedule, while threat detection monitors live traffic for attacks. They are separate features within Azure Defender for SQL.
Both fall under the 'security' umbrella and are enabled from the same Azure Defender blade, so people assume they are one feature.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
Yes and no. You can enable auditing at the server level, which covers all databases on that server for login events, but database-level auditing must be enabled separately on each database to capture queries and data changes.
Yes, a small performance overhead exists because the database engine writes logs for every audited action. For high-traffic databases, monitor storage and consider offloading old logs to cheaper storage tiers to reduce impact.
If you sent logs to Log Analytics, use Kusto Query Language (KQL) to search them — for example, `AzureDiagnostics | where Category == 'SQLSecurityAuditEvents'`. If you sent them to Azure Storage, download them as .xel files and open them in SQL Server Management Studio.
Auditing records every action for later review. Azure Defender for SQL analyses those actions in real time and sends alerts for suspicious patterns like SQL injection or brute-force attacks. You typically use both together.
No. Azure Defender for SQL (which includes threat detection) is only available for the Standard and Premium tiers, plus Azure SQL Managed Instance. The Basic tier does not support it.
Yes. In Azure Monitor, you can create custom alert rules that trigger on specific conditions in your audit logs, such as a certain user querying a sensitive table more than 100 times in an hour.
You've finished Implementing Auditing and Threat Detection. Continue through the DP-300 study guide to build a complete picture of the exam.
Done with this chapter?