ALTER SERVER AUDIT (Transact-SQL)
Alters a server audit object using the SQL Server Audit feature. For more information, see SQL Server Audit (Database Engine).
ALTER SERVER AUDIT audit_name
{
[ TO { { FILE ( <file_options> [, ...n] ) } | APPLICATION_LOG | SECURITY_LOG } ]
[ WITH ( <audit_options> [ , ...n] ) ]
[ WHERE <predicate_expression> ]
}
| REMOVE WHERE
| MODIFY NAME = new_audit_name
[ ; ]
<file_options>::=
{
FILEPATH = 'os_file_path'
| MAXSIZE = { max_size { MB | GB | TB } | UNLIMITED }
| MAX_ROLLOVER_FILES = { integer | UNLIMITED }
| MAX_FILES = integer
| RESERVE_DISK_SPACE = { ON | OFF }
}
<audit_options>::=
{
QUEUE_DELAY = integer
| ON_FAILURE = { CONTINUE | SHUTDOWN | FAIL_OPERATION }
| STATE = = { ON | OFF }
}
<predicate_expression>::=
{
[NOT ] <predicate_factor>
[ { AND | OR } [NOT ] { <predicate_factor> } ]
[,...n ]
}
<predicate_factor>::=
event_field_name { = | < > | ! = | > | > = | < | < = } { number | ' string ' }
You must specify at least one of the TO, WITH, or MODIFY NAME clauses when you call ALTER AUDIT.
You must set the state of an audit to the OFF option in order to make changes to an audit. If ALTER AUDIT is run when an audit is enabled with any options other than STATE=OFF, you will receive a MSG_NEED_AUDIT_DISABLED error message.
You can add, alter, and remove audit specifications without stopping an audit.
You cannot change an audit’s GUID after the audit has been created.
A. Changing a server audit name
The following example changes the name of the server audit HIPPA_Audit to HIPAA_Audit_Old.
USE master GO ALTER SERVER AUDIT HIPAA_Audit WITH (STATE = OFF); GO ALTER SERVER AUDIT HIPAA_Audit MODIFY NAME = HIPAA_Audit_Old; GO ALTER SERVER AUDIT HIPAA_Audit_Old WITH (STATE = ON); GO
B. Changing a server audit target
The following example changes the server audit called HIPPA_Audit to a file target.
USE master
GO
ALTER SERVER AUDIT HIPAA_Audit
WITH (STATE = OFF);
GO
ALTER SERVER AUDIT HIPAA_Audit
TO FILE (FILEPATH ='\\SQLPROD_1\Audit\',
MAXSIZE = 1000 MB,
RESERVE_DISK_SPACE=OFF)
WITH (QUEUE_DELAY = 1000,
ON_FAILURE = CONTINUE);
GO
ALTER SERVER AUDIT HIPAA_Audit
WITH (STATE = ON);
GO
C. Changing a server audit WHERE clause
The following example modifies the where clause created in example C of CREATE SERVER AUDIT (Transact-SQL). The new WHERE clause filters for the user defined event if of 27.
ALTER SERVER AUDIT [FilterForSensitiveData] WITH (STATE = OFF) GO ALTER SERVER AUDIT [FilterForSensitiveData] WHERE user_defined_event_id = 27; GO ALTER SERVER AUDIT [FilterForSensitiveData] WITH (STATE = ON); GO
D. Removing a WHERE clause
The following example removes a WHERE clause predicate expression.
ALTER SERVER AUDIT [FilterForSensitiveData] WITH (STATE = OFF) GO ALTER SERVER AUDIT [FilterForSensitiveData] REMOVE WHERE; GO ALTER SERVER AUDIT [FilterForSensitiveData] WITH (STATE = ON); GO
E. Renaming a server audit
The following example changes the server audit name from FilterForSensitiveData to AuditDataAccess.
ALTER SERVER AUDIT [FilterForSensitiveData] WITH (STATE = OFF) GO ALTER SERVER AUDIT [FilterForSensitiveData] MODIFY NAME = AuditDataAccess; GO ALTER SERVER AUDIT [AuditDataAccess] WITH (STATE = ON); GO