我已经设置了一个扩展事件来捕获“ sp_statement_completed”事件,创建它的脚本在下面。
CREATE EVENT SESSION [t1] ON SERVER ADD EVENT sqlserver.sp_statement_completedADD TARGET package0.event_file(SET filename=N'D:\DB_A\1.xel',max_file_size=(0),max_rollover_files=(0))WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF)
GO
我需要捕获每个事件的模式名称部分。
请指导我。
答案 0 :(得分:0)
尝试一下:
DECLARE @Target_Data XML =
(
SELECT TOP 1 Cast(xet.target_data AS XML) AS targetdata
FROM sys.dm_xe_session_targets AS xet
INNER JOIN sys.dm_xe_sessions AS xes ON xes.address = xet.event_session_address
WHERE xes.name = 't1'
AND xet.target_name = 'ring_buffer'
);
SELECT
xed.event_data.value('(@name)[1]', 'varchar(50)') AS event_type,
xed.event_data.value('(data[@name="object_id"]/value)[1]', 'int') AS [object_id]
INTO #HoldXEData
FROM @Target_Data.nodes('//RingBufferTarget/event') AS xed (event_data)
SELECT XE.*, O.name AS Object_name, S.name AS Schema_name
FROM #HoldXEData AS XE
INNER JOIN sys.all_objects AS O ON XE.object_id = O.object_id
INNER JOIN sys.schemas AS S ON O.schema_id = S.schema_id
DROP TABLE #HoldXEData