Friday, March 23, 2012

SQL Server - Default trace



Use the following query to find the path of the default trace

SELECT * FROM ::fn_trace_getinfo(0) ;


SELECT
     loginname,
     loginsid,
     spid,
     hostname,
     applicationname,
     servername,
     databasename,
     objectName,
     e.category_id,
     cat.name as [CategoryName],
     textdata,
     starttime,
     eventclass,
     eventsubclass,--0=begin,1=commit
     e.name as EventName
FROM ::fn_trace_gettable('M:\MSSQL10.SQL1\MSSQL\Log\log_26.trc',0)
     INNER JOIN sys.trace_events e ON eventclass = trace_event_id
     INNER JOIN sys.trace_categories AS cat ON e.category_id = cat.category_id

1 comment:

  1. found a dynamic way to get the default trace table
    http://www.simple-talk.com/sql/performance/the-default-trace-in-sql-server---the-power-of-performance-and-security-auditing/


    FROM sys.fn_trace_gettable(CONVERT(VARCHAR(150), ( SELECT TOP 1
    f.[value]
    FROM sys.fn_trace_getinfo(NULL) f
    WHERE f.property = 2
    )), DEFAULT) T
    JOIN sys.trace_events TE ON T.EventClass = TE.trace_event_id

    ReplyDelete