Skip to content

Instantly share code, notes, and snippets.

@ghotz
Created September 3, 2021 11:49
Show Gist options
  • Save ghotz/75188bb9d7b9a1a8ea4bc0a09e2ded5d to your computer and use it in GitHub Desktop.
Save ghotz/75188bb9d7b9a1a8ea4bc0a09e2ded5d to your computer and use it in GitHub Desktop.
SQLDiag snippets
-- filter columns https://docs.microsoft.com/en-us/sql/relational-databases/sql-trace/sql-trace?view=sql-server-ver15#use-data-columns-to-describe-returned-events
-- filter logical and comparison operators https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-trace-setfilter-transact-sql
SELECT * FROM sys.traces -- get trace info
EXEC sp_trace_setstatus ?, 0 -- stop trace
EXEC sp_trace_setfilter ?, 8, 0, 0, '' -- Hostname, AND, =
EXEC sp_trace_setfilter ?, 10, 7, 0, 'SQL Server Profiler' -- ApplicationName, , NOT LIKE
EXEC sp_trace_setfilter ?, 12, 0, 0, ?? -- SPID, AND, =
SELECT * FROM fn_trace_getfilterinfo(?) -- check filters
EXEC sp_trace_setstatus ?, 1 -- start trace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment