OpenMetadata
OpenMetadata copied to clipboard
MSSQL Lineage query
From the MSSQL Query:
SELECT
db.NAME database_name,
t.text query_text,
s.last_execution_time start_time,
DATEADD(ms, s.total_elapsed_time, s.last_execution_time) end_time,
NULL schema_name,
NULL query_type,
NULL user_name,
NULL aborted
FROM sys.dm_exec_cached_plans AS p
INNER JOIN sys.dm_exec_query_stats AS s
ON p.plan_handle = s.plan_handle
CROSS APPLY sys.Dm_exec_sql_text(p.plan_handle) AS t
INNER JOIN sys.databases db
ON db.database_id = t.dbid
WHERE s.last_execution_time between '{start_time}' and '{end_time}'
AND t.text NOT LIKE '/* {{"app": "OpenMetadata", %%}} */%%'
AND t.text NOT LIKE '/* {{"app": "dbt", %%}} */%%'
AND s.Prepared != 'Prepared'
ORDER BY s.last_execution_time DESC
I am not able to find CREATE or INSERT queries. Looks like MSSQL might be breaking those down into multiple internal calls (you will see them if you comment out s.Prepared != 'Prepared').
Let's validate if MSSQL offers raw query execution somehow and update the query if needed