Created
December 24, 2025 19:46
-
-
Save MarkPryceMaherMSFT/dad4dfcf7597bd634c27dac4b0c20b4b to your computer and use it in GitHub Desktop.
query to see when tables were last checked for updates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT * FROM ( | |
| select distinct eventtime,TRIM( replace(replace(replace(replace( | |
| case when CHARINDEX('END TRY',table_details) > 3 then LEFT(table_details, CHARINDEX('END TRY',table_details)-4) | |
| else table_details end, ''', N''',','),'N''',''),''';',''),'''','')) as bl_details | |
| from ( | |
| select *, CHARINDEX('sys.fn_cdc_get_min_lsn(',SQLText) no_, | |
| SUBSTRING(SQLText,CHARINDEX('sys.fn_cdc_get_min_lsn(',SQLText) + len('sys.fn_cdc_get_min_lsn('),150) sss_ | |
| , | |
| case when CHARINDEX('sys.sp_cdc_help_change_data_capture',SQLText) > 0 then SUBSTRING(SQLText,CHARINDEX('sys.sp_cdc_help_change_data_capture',SQLText) + len('sys.sp_cdc_help_change_data_capture'),150) | |
| when CHARINDEX('cdc_get_ddl_history',SQLText) > 0 then SUBSTRING(SQLText,CHARINDEX('cdc_get_ddl_history @capture_instance = ',SQLText) + len('cdc_get_ddl_history @capture_instance = '),150) | |
| when CHARINDEX('sys.fn_cdc_get_min_lsn(',SQLText) > 0 then SUBSTRING(SQLText,CHARINDEX('sys.fn_cdc_get_min_lsn(',SQLText) + len('sys.fn_cdc_get_min_lsn('),150) | |
| else '' end table_details | |
| from ( | |
| SELECT | |
| X.event_xml.value('(event/@name)[1]', 'varchar(50)') AS EventName, | |
| X.event_xml.value('(event/action[@name="sql_text"]/value)[1]', 'nvarchar(max)') AS SQLText, | |
| X.event_xml.value('(event/action[@name="database_name"]/value)[1]', 'varchar(128)') AS DatabaseName, | |
| X.event_xml.value('(event/action[@name="username"]/value)[1]', 'varchar(128)') AS UserName, | |
| X.event_xml.value('(event/@timestamp)[1]', 'datetime') AS EventTime | |
| FROM sys.fn_xe_file_target_read_file('C:\XE2\MonitorTableQueries*.xel', NULL, NULL, NULL) AS F | |
| CROSS APPLY (SELECT CAST(F.event_data AS XML)) AS X(event_xml) ) t ) y ) q | |
| where len(bl_details) > 0 | |
| and bl_details like '%tbl_100%' | |
| ORDER BY q.EventTime DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment