{"id":1426,"date":"2026-05-01T19:27:16","date_gmt":"2026-05-01T19:27:16","guid":{"rendered":"https:\/\/infinitechno.com\/techno\/?p=1426"},"modified":"2026-05-01T19:29:24","modified_gmt":"2026-05-01T19:29:24","slug":"steps-to-enable-sql-database-auditing-effectively","status":"publish","type":"post","link":"https:\/\/infinitechno.com\/techno\/2026\/05\/01\/steps-to-enable-sql-database-auditing-effectively\/","title":{"rendered":"Steps to Enable SQL Database Auditing Effectively"},"content":{"rendered":"\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"683\" height=\"1024\" src=\"https:\/\/infinitechno.com\/techno\/wp-content\/uploads\/2026\/05\/Im1JF4r8lZ21777663013-683x1024.jpeg\" alt=\"\" class=\"wp-image-1428\" srcset=\"https:\/\/infinitechno.com\/techno\/wp-content\/uploads\/2026\/05\/Im1JF4r8lZ21777663013-683x1024.jpeg 683w, https:\/\/infinitechno.com\/techno\/wp-content\/uploads\/2026\/05\/Im1JF4r8lZ21777663013-200x300.jpeg 200w, https:\/\/infinitechno.com\/techno\/wp-content\/uploads\/2026\/05\/Im1JF4r8lZ21777663013-768x1152.jpeg 768w, https:\/\/infinitechno.com\/techno\/wp-content\/uploads\/2026\/05\/Im1JF4r8lZ21777663013-600x900.jpeg 600w, https:\/\/infinitechno.com\/techno\/wp-content\/uploads\/2026\/05\/Im1JF4r8lZ21777663013.jpeg 1024w\" sizes=\"auto, (max-width: 683px) 100vw, 683px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary><\/summary><\/details>\n<\/div><\/div>\n<\/div>\n<\/div>\n\n<p class=\"wp-block-paragraph\"><strong>Step 1: Create an Audit Object<\/strong><strong><\/strong><\/p>\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n<p class=\"wp-block-paragraph\">Download PDF: <a href=\"https:\/\/infinitechno.com\/techno\/wp-content\/uploads\/2026\/05\/Configure-SQL-Server-Database-AuditliuNdA1z1777663118.pdf\">Configure SQL Server Database Audit<\/a><\/p>\n\n<p class=\"wp-block-paragraph\">USE master;<br>GO<br><br>CREATE SERVER AUDIT Audit_SQL_Tracking<br>TO FILE<br>(<br>&nbsp;&nbsp;&nbsp;&nbsp;FILEPATH = &#8216;C:\\SQLAudit\\&#8217;, &nbsp;&nbsp;&#8212; make sure folder exists<br>&nbsp;&nbsp;&nbsp;&nbsp;MAXSIZE = 100 MB,<br>&nbsp;&nbsp;&nbsp;&nbsp;MAX_ROLLOVER_FILES = 10<br>)<br>WITH (ON_FAILURE = CONTINUE);<br>GO<\/p>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<p class=\"wp-block-paragraph\"><strong>Step 2: Enable the Audit<\/strong><strong><\/strong><\/p>\n\n<p class=\"wp-block-paragraph\">ALTER SERVER AUDIT Audit_SQL_Tracking<br>WITH (STATE = ON);<br>GO<\/p>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<p class=\"wp-block-paragraph\"><strong>\u2705<\/strong><strong>&nbsp;2. Create Database-Level Audit Specification<\/strong><strong><\/strong><\/p>\n\n<p class=\"wp-block-paragraph\">Now we define <strong>what actions to track inside a specific database<\/strong>.<\/p>\n\n<p class=\"wp-block-paragraph\">USE YourDatabaseName;<br>GO<br><br>CREATE DATABASE AUDIT SPECIFICATION Audit_DB_Tracking<br>FOR SERVER AUDIT Audit_SQL_Tracking<\/p>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<p class=\"wp-block-paragraph\"><strong>\u2705<\/strong><strong>&nbsp;3. Add Audit Actions (Your Requirements)<\/strong><strong><\/strong><\/p>\n\n<p class=\"wp-block-paragraph\">You asked to track:<\/p>\n\n<ul class=\"wp-block-list\">\n<li>CREATE TABLE<\/li>\n\n\n\n<li>DROP TABLE<\/li>\n\n\n\n<li>DELETE<\/li>\n\n\n\n<li>CREATE PROCEDURE<\/li>\n\n\n\n<li>DROP PROCEDURE<\/li>\n<\/ul>\n\n<p class=\"wp-block-paragraph\">Here\u2019s the full script:<\/p>\n\n<p class=\"wp-block-paragraph\">ALTER DATABASE AUDIT SPECIFICATION Audit_DB_Tracking<br>ADD (SCHEMA_OBJECT_CHANGE_GROUP), &nbsp;&nbsp;&#8212; CREATE \/ ALTER \/ DROP tables, procedures, views<br>ADD (DELETE ON DATABASE::YourDatabaseName BY PUBLIC), &nbsp;&#8212; DELETE operations<br>ADD (SCHEMA_OBJECT_ACCESS_GROUP); &nbsp;&#8212; Access tracking (optional but useful)<br>GO<\/p>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<p class=\"wp-block-paragraph\"><strong>What Each Option Means<\/strong><\/p>\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Option<\/strong><strong><\/strong><\/td><td><strong>Tracks<\/strong><strong><\/strong><\/td><\/tr><tr><td>SCHEMA_OBJECT_CHANGE_GROUP<\/td><td>CREATE, ALTER, DROP (tables, procedures, etc.)<\/td><\/tr><tr><td>DELETE<\/td><td>Tracks DELETE statements<\/td><\/tr><tr><td>SCHEMA_OBJECT_ACCESS_GROUP<\/td><td>SELECT, EXECUTE (optional)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<p class=\"wp-block-paragraph\"><strong>\u2705<\/strong><strong>&nbsp;4. Enable Database Audit<\/strong><strong><\/strong><\/p>\n\n<p class=\"wp-block-paragraph\">ALTER DATABASE AUDIT SPECIFICATION Audit_DB_Tracking<br>WITH (STATE = ON);<br>GO<\/p>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<p class=\"wp-block-paragraph\"><strong>\u2705<\/strong><strong>&nbsp;5. View Audit Logs<\/strong><strong><\/strong><\/p>\n\n<p class=\"wp-block-paragraph\">You can read audit logs using:<\/p>\n\n<p class=\"wp-block-paragraph\">SELECT *<br>FROM sys.fn_get_audit_file (<br>&nbsp;&nbsp;&nbsp;&nbsp;&#8216;C:\\SQLAudit\\*.sqlaudit&#8217;,<br>&nbsp;&nbsp;&nbsp;&nbsp;DEFAULT,<br>&nbsp;&nbsp;&nbsp;&nbsp;DEFAULT<br>);<\/p>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<p class=\"wp-block-paragraph\"><strong>\u2705<\/strong><strong>&nbsp;6. Filter Specific Events (Example)<\/strong><strong><\/strong><\/p>\n\n<p class=\"wp-block-paragraph\">Only show DELETE operations:<\/p>\n\n<p class=\"wp-block-paragraph\">SELECT event_time, action_id, statement<br>FROM sys.fn_get_audit_file (<br>&nbsp;&nbsp;&nbsp;&nbsp;&#8216;C:\\SQLAudit\\*.sqlaudit&#8217;,<br>&nbsp;&nbsp;&nbsp;&nbsp;DEFAULT,<br>&nbsp;&nbsp;&nbsp;&nbsp;DEFAULT<br>)<br>WHERE action_id = &#8216;DL&#8217;; &nbsp;&#8212; DELETE<\/p>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":1428,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"pagelayer_contact_templates":[],"_pagelayer_content":"","_glsr_average":0,"_glsr_ranking":0,"_glsr_reviews":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[49,91],"tags":[],"class_list":["post-1426","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mssql","category-sql-server-best-practices"],"acf":[],"jetpack_featured_media_url":"https:\/\/infinitechno.com\/techno\/wp-content\/uploads\/2026\/05\/Im1JF4r8lZ21777663013.jpeg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/infinitechno.com\/techno\/wp-json\/wp\/v2\/posts\/1426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/infinitechno.com\/techno\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/infinitechno.com\/techno\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/infinitechno.com\/techno\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/infinitechno.com\/techno\/wp-json\/wp\/v2\/comments?post=1426"}],"version-history":[{"count":3,"href":"https:\/\/infinitechno.com\/techno\/wp-json\/wp\/v2\/posts\/1426\/revisions"}],"predecessor-version":[{"id":1431,"href":"https:\/\/infinitechno.com\/techno\/wp-json\/wp\/v2\/posts\/1426\/revisions\/1431"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/infinitechno.com\/techno\/wp-json\/wp\/v2\/media\/1428"}],"wp:attachment":[{"href":"https:\/\/infinitechno.com\/techno\/wp-json\/wp\/v2\/media?parent=1426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/infinitechno.com\/techno\/wp-json\/wp\/v2\/categories?post=1426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/infinitechno.com\/techno\/wp-json\/wp\/v2\/tags?post=1426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}