Sql-Server
添加到伺服器端跟踪的所有可能過濾器是什麼?
下面的程式碼過濾跟踪文件以僅擷取數據庫“AdventureWorks”上發生的事件
-- Set the Filters declare @intfilter int declare @bigintfilter bigint set @bigintfilter = 1000000 exec sp_trace_setfilter @TraceID, 13, 0, 4, @bigintfilter exec sp_trace_setfilter @TraceID, 35, 0, 6, N'AdventureWorks' -- Set the trace status to start exec sp_trace_setstatus @TraceID, 1
從上面的例子:
什麼是 13?
我知道 35 必須是數據庫名稱。
我怎樣才能找到其他選項(主機名、程序、對象名等?)它們儲存在哪裡?哪個系統表或視圖?
我發現這個連結很有幫助: Need sp_trace_setfilter xref list of @columnid parameters
從這個問題:找出跟踪文件中的列
有這個腳本
-- Gets all Events for a given trace id SELECT a.[EventID], b.[name] AS [Even Name], a.[ColumnID], c.[name] AS [Column Name], d.[name] AS [Category] FROM fn_trace_geteventinfo(<trace ID>) AS a --<<Put the trace ID you are interested in INNER JOIN sys.trace_events AS b ON a.EventID = b.Trace_Event_ID INNER JOIN sys.trace_columns AS c ON a.ColumnID = c.Trace_Column_ID INNER JOIN sys.trace_categories AS d ON b.Category_ID = d.Category_ID ORDER BY a.[EventID], a.[ColumnID]
由於 DMV sys.trace_columns ,它顯示了跟踪的所有列
我已經使用以下過濾器設置了伺服器端跟踪:(這是腳本的一部分)
-- Set the Filters declare @intfilter int declare @bigintfilter bigint exec sp_trace_setfilter @TraceID, 10, 0, 7, N'SQL Server Profiler - 53e0541a-7b74-4fce-bcac-9255e79a6372' exec sp_trace_setfilter @TraceID, 34, 1, 6, N'udpProductTaxRateGet' exec sp_trace_setfilter @TraceID, 34, 1, 6, N'udpProductBulletPointSelectByTier1NoteTypeCode' exec sp_trace_setfilter @TraceID, 35, 1, 6, N'US16AUTPProduct' -- Set the trace status to start exec sp_trace_setstatus @TraceID, 1 -- display trace id for future references select TraceID=@TraceID
當我現在執行這個查詢時,我可以看到那裡有哪些列,以及過濾器的確切工作方式。
------------------------------------------------------------ -- what filters are set on @traceid -- and how they are working -- marcelo miorelli sql server 2005 - 8-8-2016 ------------------------------------------------------------ declare @traceid int select @traceid = 2 select a.[columnid] ,c.[type_name] ,c.[name] as [Column Name] ,[ @comparison_operator ] = CASE A.comparison_operator WHEN 0 THEN '= (Equal)' WHEN 1 THEN '<> (Not Equal)' WHEN 2 THEN '> (Greater Than)' WHEN 3 THEN '< (Less Than)' WHEN 4 THEN '>= (Greater Than Or Equal)' WHEN 5 THEN '<= (Less Than Or Equal)' WHEN 6 THEN 'LIKE' WHEN 7 THEN 'NOT LIKE' ELSE 'NOT SURE' END ,a.value ,[ @logical_operator ] = CASE A.LOGICAL_OPERATOR WHEN 1 THEN 'OR' ELSE 'AND' END from fn_trace_getfilterinfo( @traceid ) a INNER JOIN sys.trace_columns AS c ON a.ColumnID = c.Trace_Column_ID
–
$$ @logical_operator = $$邏輯運算符 – 指定是應用 AND (0) 還是 OR (1) 運算符。
–logical_operator 是 int,沒有預設值。