Audit DB Using A New SQL Server Audit Object
Audit DB Using A New SQL Server Audit Object
1
4. By default, the newly created audit object is disabled. The disabled status is indicated by
a red x. to enable the Audit
2
To apply the audit activity to a specific database
expand the node of the database to audit Security, right-click Database Audit
Specifications select New Database Audit Specification
6. In the Create Database Audit Specification dialog, indicate the specification name,
associate the specification with the audit object created in the previous step,
7. Specify the activity to audit in the Audit Action Type(all actions that can be audited using
SQL Server Auditing are listed) indicate the database, object, or schema as an Object
Class, the name of the audited object, and principal Name
3
8. Database audit specifications are disabled, by default. To enable them, select this option
in the context menu
Expand Security Expand Audits Right Click the Audit log …View Audit Logs
4
Using T-SQL
To create an Audit Object
CREATE SERVER AUDIT Sample_Audit
TO FILE ( FILEPATH ='E:\Audittest\' );
To Enable Audit
ALTER SERVER AUDIT Sample_Audit
WITH (STATE = ON);
GO
To Create Audit Specification
USE STUDENTGRADE
CREATE DATABASE AUDIT SPECIFICATION [ Sample
DatabaseAuditSpecification]
FOR SERVER AUDIT [Sample_Audit]
ADD (DATABASE_OBJECT_ACCESS_GROUP),
ADD (DATABASE_OBJECT_CHANGE_GROUP),
ADD (DELETE ON DATABASE::[STUDENTGRADE] BY [dbo]),
ADD (INSERT ON DATABASE::[STUDENTGRADE] BY [dbo]),
ADD (SELECT ON DATABASE::[STUDENTGRADE] BY [dbo]),
ADD (UPDATE ON DATABASE::[STUDENTGRADE] BY [dbo])
WITH (STATE = OFF)
GO
To enable Audit specification
USE STUDENTGRADE
ALTER DATABASE AUDIT SPECIFICATION SampleDatabaseAuditSpecification
FOR SERVER AUDIT [Sample_Audit]
WITH (STATE = ON);
GO
5
Use fn_get_audit_file to view the audit log
Note
The audit report for example for data deletion event include user who made the deletion,
and when the deletion was made are but not the actual deleted data which is a
disadvantage for users who need more comprehensive audit data.
It is difficult to manage multiple instances and consolidate the audit data and there is a lot
of work involved in managing, analyzing and archiving audit data, whether in a file or
log, and necessitates manual effort for importing, archiving and reporting.