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 [distributed_statement_id], | |
| [database_name], | |
| [submit_time], | |
| [start_time], | |
| [end_time], | |
| [is_distributed], | |
| [statement_type], | |
| [total_elapsed_time_ms], | |
| [login_name], | |
| [row_count], |
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 | |
| s.name AS SchemaName, | |
| t.name AS TableName, | |
| c.name AS ColumnName, | |
| ty.name AS DataType, | |
| c.max_length, | |
| c.precision, | |
| c.scale, | |
| c.is_nullable | |
| FROM sys.tables t |
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
| declare @list varchar(max) | |
| declare @sql nvarchar(max) | |
| drop table if exists sys_tables | |
| create table sys_tables (object_id bigint, tablename varchar(50)) | |
| SELECT @list = STRING_AGG('(' + CAST([object_id] AS VARCHAR(20)) + ', ''' + CAST([name] AS VARCHAR(128)) + ''')', ',') FROM sys.tables | |
| SET @sql = 'INSERT INTO sys_tables (object_id, tablename) VALUES ' + @list | |
| --print @sql | |
| exec sp_executesql @sql | |
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) |
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 | |
| 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:\XE\MonitorTableQueries*.xel', NULL, NULL, NULL) AS F | |
| CROSS APPLY (SELECT CAST(F.event_data AS XML)) AS X(event_xml) | |
| ORDER BY EventTime DESC; |
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
| -- Create Extended Events session | |
| CREATE EVENT SESSION [MonitorTableQueries] | |
| ON SERVER | |
| ADD EVENT sqlserver.sql_statement_completed | |
| ( | |
| ACTION ( | |
| sqlserver.sql_text, | |
| sqlserver.database_name, | |
| sqlserver.username | |
| ) |
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
| -- Stop the Extended Events session if it is running | |
| IF EXISTS ( | |
| SELECT 1 | |
| FROM sys.server_event_sessions | |
| WHERE name = 'MonitorTableQueries' | |
| ) | |
| BEGIN | |
| ALTER EVENT SESSION [MonitorTableQueries] ON SERVER STATE = STOP; | |
| PRINT 'MonitorTableQueries session stopped.'; |
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
| -- Create Extended Events session | |
| CREATE EVENT SESSION [MonitorTableQueries] | |
| ON SERVER | |
| ADD EVENT sqlserver.sql_statement_completed | |
| ( | |
| ACTION ( | |
| sqlserver.sql_text, | |
| sqlserver.database_name, | |
| sqlserver.username |
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
| IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[help_change_feed]') AND type in (N'U')) DROP TABLE [dbo].[help_change_feed] | |
| create table help_change_feed | |
| ( | |
| table_group_id uniqueidentifier , | |
| table_group_name nvarchar(140) , | |
| destination_location nvarchar(512) , | |
| destination_credential nvarchar(247) , | |
| destination_type nvarchar(247) , | |
| workspace_id nvarchar(247) , |
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
| %%pyspark | |
| import sempy.fabric as fabric | |
| import struct | |
| import sqlalchemy | |
| import pyodbc | |
| import pandas as pd | |
| from notebookutils import mssparkutils | |
| #Function to Return sqlalchemt ODBC Engine, given a connection string and using Integrated AAD Auth to Fabric |
NewerOlder