-
Notifications
You must be signed in to change notification settings - Fork 681
/
SchemaQueryByUser.sql
30 lines (26 loc) · 1.68 KB
/
SchemaQueryByUser.sql
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
/*
Original link: https://gist.github.com/SQLDBAWithABeard/3a617e04de5db729e941a0fd6ebed7cc
Author: Rob Sewell
*/
/* Stop trace if started */
IF EXISTS (SELECT * FROM sys.dm_xe_sessions WHERE name = 'SchemaQueryByUser')
ALTER EVENT SESSION SchemaQueryByUser ON SERVER STATE = STOP;
/* Delete trace if exists */
IF EXISTS (SELECT * FROM sys.server_event_sessions WHERE name = 'SchemaQueryByUser')
DROP EVENT SESSION SchemaQueryByUser ON SERVER;
/* Create trace */
CREATE EVENT SESSION SchemaQueryByUser ON SERVER
ADD EVENT sqlserver.sql_batch_completed(SET collect_batch_text=(1)
ACTION(sqlserver.database_name, sqlserver.session_server_principal_name)
WHERE ((((((((NOT ([sqlserver].[like_i_sql_unicode_string]([sqlserver].[session_server_principal_name],N'EZCORP\Y%')))
AND (([sqlserver].[like_i_sql_unicode_string]([batch_text],N'%%'))
OR ([sqlserver].[equal_i_sql_unicode_string]([sqlserver].[database_name],N''))))
AND (NOT ([sqlserver].[like_i_sql_unicode_string]([batch_text],N'%SELECT CASE WHEN has_dbaccess%END%'))))
AND (NOT ([sqlserver].[like_i_sql_unicode_string]([batch_text],N'%SELECT case when @edition = N''SQL Azure''%'))))
AND (NOT ([sqlserver].[like_i_sql_unicode_string]([batch_text],N'%SERVERPROPERTY(%'))))
AND (NOT ([sqlserver].[like_i_sql_unicode_string]([batch_text],N'%HasMemoryOptimizedObjects from master.sys.master_files mf join master.sys.databases db on mf.database_id%'))))
AND (NOT ([sqlserver].[like_i_sql_unicode_string]([batch_text],N'%database_query_store_options%'))))
AND (NOT ([sqlserver].[like_i_sql_unicode_string]([batch_text],N'%SET SHOWPLAN%')))))
GO
ALTER EVENT SESSION SchemaQueryByUser ON SERVER STATE = START;
GO