By product  
  Other  

Knowledgebase

Tips and How-to Articles for ApexSQL Tools


How to audit only some users in ApexSQLAudit?

Applies to
ApexSQL Audit

Description

This article discusses how to audit only some of the users with ApexSQL Audit


Solution
To do this, the Trigger template has to be modified
1. Click the Template editor in the Outlook auditing bar




The Template editor will be opened



2. Find the code where the trigger for INSERT command is created

'==================================================
'INSERT INSERT INSERT INSERT
'==================================================

caption = "Create Insert Trigger " & "[" & objTable.Owner & "].[" & StartTriggerNameInsert & objTable.Name & "]" & _ ">" for Table " & TableFullName%}
IF OBJECT_ID('{%Audit.Print replace("[" & objTable.Owner & "].[" & StartTriggerNameInsert & objTable.Name & "]", "'", "''") %}','TR') IS NOT NULL
BEGIN
DROP TRIGGER {%Audit.Print "[" & objTable.Owner & "].[" & StartTriggerNameInsert & objTable.Name & "]" %}
PRINT '{% Audit.Print "Trigger Dropped: " & StartTriggerNameInsert & Replace(objTable.Name,"'","''")%}'
END
GO
-- {%Audit.Print caption%}
Print '{%Audit.Print Replace(caption, "'", "''")%}'
go
CREATE TRIGGER {%Audit.Print "[" & objTable.Owner & "].[" & StartTriggerNameInsert & objTable.Name & "]" %}
ON {%Audit.Print TableFullName%}
FOR INSERT
NOT FOR REPLICATION
As
-- "SQLAUDIT GENERATED - DO NOT REMOVE"
-- -------------------------------------------------------------------------------------------
-- Legal: {%Audit.Print Audit.Legal%}
-- Description: INSERT TRIGGER for Table: {%Audit.Print TableFullName%}
-- Author: {%Audit.Print Audit.Author%}
-- Date: {%Audit.Print Now%}
-- -------------------------------------------------------------------------------------------
BEGIN



3. Add the following:


IF (SUSER_SNAME() <> N'ComputerName\UserName1') AND (SUSER_NAME() <> N'ComputerName\UserName2') RETURN


In case of Windows Authentication, use ComputerName\UserName1 and ComputerName\UserName2 for user names you want to include in auditing
In case of SQL Authentication, use UserName1 and UserName2 instead

4. Modify the template for UPDATE by adding the same code
'==================================================
' UPDATE UPDATE UPDATE UPDATE UPDATE
'==================================================


5. Modify the template for DELETE by adding the same code
'==================================================
' DELETE DELETE DELETE DELETE
'==================================================


6. Create the triggers. If the triggers already exist, recreate them

Last updated
November 30,2011

Labels:



© 2012 ApexSQL LLC All rights reserved | (919) 968-8444 | Contact us | Terms of use | Privacy policy