Re: SQL 2005 - audit SELECT statements?



Joe
Look at Dejan's example


For example, let?s say we want to follow selects on the Customers table of
the Northwind database. Create a trace with only the following settings:

- SP:StmtCompleted and SQL: StmtCompleted events

- EventClass, TextData, ApplicationName and SPID columns

- DatabaseID Equals 6 (DB_ID() of the Northwind database) and
TextData Like select%customers% filters

- Name the trace SelectTrigger and save it to a table with the same
name in the Northwind database.

Start the trace, and create the following trigger using Query Analyzer:



CREATE TRIGGER TraceSelectTrigger ON SelectTrigger

FOR INSERT

AS

EXEC master.dbo.xp_logevent 60000, 'Select from Customers happened!',
warning



Now check how trigger works by performing couple of selects:



SELECT TOP 1 *

FROM Customers

SELECT TOP 1 *

FROM Orders

SELECT TOP 1 c.CustomerID

FROM Customers c INNER JOIN Orders o

ON c.CustomerID=o.CustomerID



With Event Viewer, check whether you got two warnings in the Application log
for the 1st and the 3rd queries (the 2nd should be filtered out).


"Joe" <joe@xxxxxxxxxxx> wrote in message
news:ejSDFLNMGHA.2528@xxxxxxxxxxxxxxxxxxxxxxx
Hi!

Any ideas on how to audit *select* statements with SQL 2005?

This is a pretty common requirement with databases where one needs to keep
track of who-saw-what.
Oracle has had it for ages... wasn't able to find it anywhere for sql
2005... but need the functionallity.

Regards,

Joe





.



Relevant Pages

  • Re: Database Table usage
    ... name in the Northwind database. ... and create the following trigger using Query Analyzer: ... FROM Customers ... FROM Customers c INNER JOIN Orders o ...
    (microsoft.public.sqlserver.server)
  • Re: i would like to see who executed a select statement on a specific table
    ... name in the Northwind database. ... and create the following trigger using Query Analyzer: ... FROM Customers ... FROM Customers c INNER JOIN Orders o ...
    (microsoft.public.sqlserver.security)
  • Re: Why cant i find a row in a dataset?
    ... > Currently had a Dataset that has information from the Northwind database, ... > Customers table in it. ... why when I enter ALFKI in txtCustomerID.Text is it not ... > Paul Custance ...
    (microsoft.public.dotnet.framework)
  • Re: Anyone know how to add a "Debug window" in own app
    ... Because TRACE is defined in Release builds by VS.NET. ... config file to remove the default trace listener, ... appears as if you are using your customers to do your QA. ...
    (microsoft.public.dotnet.framework)
  • Re: Linq Sum() Question
    ... I made a console application that makes use of Northwind database. ... Made a dbml file of the database whith the designer and now I want to ... see the total of all orders of the customers. ...
    (microsoft.public.dotnet.languages.csharp)