-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGenMetadata.sql
More file actions
66 lines (61 loc) · 1.65 KB
/
GenMetadata.sql
File metadata and controls
66 lines (61 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- class definitions
select
z.Tag
, z.Parent
, z.ClassId [EventClass!1!Id]
, z.Category [EventClass!1!Category]
, z.Name [EventClass!1!Name]
, z.Name [EventClass!1!ClassName]
, z.ColId [Col!2!Id]
, z.ColName [Col!2!Name]
from (
select
1 as Tag
, NULL as Parent
, e.trace_event_id as ClassId
, c.name as Category
, e.name as Name
, NULL as ColId
, NULL as ColName
from sys.trace_events e
join sys.trace_categories c on e.category_id = c.category_id
where c.name = N'Security Audit'
UNION ALL
select
2 as Tag
, 1 as Parent
, e.trace_event_id as ClassId
, NULL as Category
, NULL as Name
, c.trace_column_id
, c.name
from sys.trace_events e
join sys.trace_event_bindings ec on e.trace_event_id = ec.trace_event_id
join sys.trace_columns c on ec.trace_column_id = c.trace_column_id
join sys.trace_categories cat on e.category_id = cat.category_id
where cat.name = N'Security Audit'
) z
order by z.ClassId, z.Tag
for xml explicit
-- Columns query (so we don't have to keep redefining the membername and have discrepencies
select
c.trace_column_id [@ColId]
, c.name [@ColName]
, c.Name [@MemberName]
, CASE c.name WHEN N'EventSequence' THEN 'bigint' ELSE c.type_name END [@ColType]
, case c.type_name when N'nvarchar' then c.max_size /2
else c.max_size
end [@ColMaxSize]
from sys.trace_columns c
for xml path ('Column')
select
e.trace_event_id as [@Id]
--, c.name as [@Category]
, e.name as [@Name]
--, NULL as [@ColId]
--, NULL as [@ColName]
from sys.trace_events e
join sys.trace_categories c on e.category_id = c.category_id
where c.name = N'Security Audit'
order by 2
--for xml path (N'EventClass')