Audit access tracks who reads, modifies, or deletes data and logs the activity for compliance and troubleshooting.
Audit access records login attempts and data-level actions, writing them to a server or file target so security teams can review who touched sensitive data.
Enable auditing when your ecommerce app stores PII, processes payments, or must meet SOC 2/GDPR requirements. Start before going to production to capture a full history.
Run CREATE SERVER AUDIT to define the log target, then CREATE SERVER AUDIT SPECIFICATION to choose audit actions such as SUCCESSFUL_LOGIN_GROUP.
CREATE SERVER AUDIT Audit_Login_Access
TO FILE (FILEPATH = 'C:\AuditLogs\')
WITH (ON_FAILURE = CONTINUE);
CREATE SERVER AUDIT SPECIFICATION Audit_Login_Spec
FOR SERVER AUDIT Audit_Login_Access
ADD (SUCCESSFUL_LOGIN_GROUP),
ADD (FAILED_LOGIN_GROUP);
ALTER SERVER AUDIT Audit_Login_Access WITH (STATE = ON);
ALTER SERVER AUDIT SPECIFICATION Audit_Login_Spec WITH (STATE = ON);
Create a DATABASE AUDIT SPECIFICATION and add action groups such as SELECT, INSERT, UPDATE, and DELETE for the Orders or Customers tables.
USE EcommerceDB;
GO
CREATE DATABASE AUDIT SPECIFICATION Audit_OrderTable
FOR SERVER AUDIT Audit_Login_Access
ADD (SELECT, INSERT, UPDATE, DELETE ON dbo.Orders BY PUBLIC);
GO
ALTER DATABASE AUDIT SPECIFICATION Audit_OrderTable WITH (STATE = ON);
Logs are written to the FILEPATH you specify or to the Windows Application log. Query sys.fn_get_audit_file to read them in SQL Server.
Limit action groups to what you need, archive audit files to cheaper storage, and test performance impact in staging. Rotate files with MAXSIZE to prevent disk-full errors.
Yes. Point FILEPATH to a network share or write to the Windows security log for centralized collection.
Minimal overhead (1-5 %) when capturing specific actions. Wide-open audits can cause noticeable latency.
Use sys.fn_get_audit_file('C:\AuditLogs\*', NULL, NULL) or open the .sqlaudit file in SSMS Log File Viewer.