Share via

How do filter Action column on SQL Database Audit Specification?

Urbel 665 Reputation points
2026-06-19T04:24:08.43+00:00

Hi Expert,

How to exclude Column [Action ID] with record 'SELECT','EXECUTE' & 'VIEW' action?

I've filtered [Action ID] using conversion to INT type to getting ID of the action(Select,Execute,View)

but it still not worked ..

any suggestion?

great thanks for all respond

warm regards,

UrBel

SQL Server Database Engine

Answer accepted by question author

Erland Sommarskog 135.1K Reputation points MVP Volunteer Moderator
2026-06-19T21:35:20.1833333+00:00

So while you could filter the server audit by the actions, that seems heavy-handed. Why not set up the database audit specification to only capture the operations you want:

CREATE DATABASE AUDIT SPECIFICATION AuditSpec FOR SERVER AUDIT YourServerAudit
   ADD (INSERT, UPDATE, DELETE ON dbo.Orders BY public)
WITH (STATE = ON)

Was this answer helpful?

3 people found this answer helpful.
0 comments No comments

Answer accepted by question author

Deepesh Dhake 245 Reputation points
2026-06-19T18:23:55.5366667+00:00

Did you try this?

-- after generating a SELECT and an EXECUTE event, find their integers: 
SELECT DISTINCT action_id, CAST(action_id AS INT) AS action_id_int FROM sys.fn_get_audit_file('C:\YourAuditPath\*.sqlaudit', NULL, NULL) WHERE action_id IN ('SL ', 'EX '); 
-- then: 
ALTER SERVER AUDIT [YourServerAuditName] WITH (STATE = OFF); 
ALTER SERVER AUDIT [YourServerAuditName] WHERE (action_id <> <SELECT_int> AND action_id <> <EXECUTE_int>); 
ALTER SERVER AUDIT [YourServerAuditName] WITH (STATE = ON);

Was this answer helpful?

2 people found this answer helpful.

Answer accepted by question author

AI answer

2026-06-19T04:24:19.75+00:00

In SQL Server Audit, the action_id column in the audit log is a varchar(4), not an int. To filter out specific actions such as SELECT, EXECUTE, and VIEW in a database audit specification, use the audit action names and their corresponding action_id values from sys.dm_audit_actions, and filter on the character action_id (not by converting it to int).

General approach:

  1. Find the action_id values for the actions to exclude:
       SELECT action_id, name
       FROM sys.dm_audit_actions
       WHERE name IN ('SELECT', 'EXECUTE', 'VIEW DEFINITION');
    
  2. Use those action_id values in the audit predicate or in queries against the audit log, for example:
       SELECT *
       FROM sys.fn_get_audit_file('your_audit_path', NULL, NULL)
       WHERE action_id NOT IN ('SLCT', 'EX', 'VWDF');  -- sample IDs; use actual values from step 1
    

Key points:

  • action_id in the audit log and in sys.dm_audit_actions is varchar(4) and should be compared as text.
  • Use sys.dm_audit_actions to map between the human-readable action name (SELECT, EXECUTE, VIEW DEFINITION, etc.) and the action_id used in audit records.
  • Do not convert action_id to int for filtering; that breaks the match and causes the filter to fail.

References:

AI-generated content may be incorrect. Read our transparency notes for more information.

Was this answer helpful?

2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.