Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
sp_audit_write (Transact-SQL)
Collapse the table of content
Expand the table of content

sp_audit_write (Transact-SQL)

 

Applies To: SQL Server 2014, SQL Server 2016 Preview

Adds a user-defined audit event to the USER_DEFINED_AUDIT_GROUP. If USER_DEFINED_AUDIT_GROUP is not enabled, sp_audit_write is ignored.

Applies to: SQL Server (SQL Server 2012 through current version).

Topic link icon Transact-SQL Syntax Conventions

sp_audit_write [ @user_defined_event_id =  ] user_defined_event_id , 
        [ @succeeded =  succeeded 
    [ , [ @user_defined_information =  ] 'user_defined_information' ] 
    [ ; ]

@user_defined_event_id

A parameter defined by the user and recorded in the user_defined_event_id column of the audit log. @user_defined_event_id is type smallint.

@succeeded

A parameter passed by user to indicate whether the event was successful or not. This appears in the succeeded column of the audit log. @succeeded is bit.

@user_defined_information

Is the text defined by the user and recorded in the new user_defined_event_id column of the audit log. @user_defined_information is nvarchar(4000).

0 (success) or 1 (failure)

Failures are caused by incorrect input parameters or failure to write to the target audit log.

When the USER_DEFINED_AUDIT_GROUP is added to either a server audit specification or a database audit specification, the event triggered by sp_audit_write will be included in the audit log.

Requires membership in the public database role.

The following example creates an audit event with the id 27, the succeeded value of 0, and included optional informational text.

EXEC sp_audit_write @user_defined_event_id =  27 , 
              @succeeded =  0 
            , @user_defined_information = N'Access to a monitored object.' ;

The following example creates an audit event with the id 27, the succeeded value of 0, and does not include optional informational text or the optional parameter names.

EXEC sp_audit_write 27, 0;

Community Additions

ADD
Show:
© 2015 Microsoft