dmv

Check if SQL object is referenced by any other SQL objects

孤者浪人 提交于 2019-12-31 06:13:08
问题 I was just reading this SO thread and had a question for @Mack regarding whether there is a way to check if a SQL object is referenced by any other SQL objects. He (@Mack) used T-SQL and DMVs to accomplish something similar in his answer. Is this possible, if so how? I would have posted this as a comment, but I don't have sufficient reputation yet... 回答1: You can, but not with a DMV instead you'll need a related dynamic management function (DMF) dm_sql_referencing_entities (more info here).

DMF sys.dm_exec_sql_text not showing DBID

限于喜欢 提交于 2019-12-23 12:11:15
问题 I have got this query from http://technet.microsoft.com/en-us/library/ms181929.aspx SELECT s2.dbid, s1.sql_handle, (SELECT TOP 1 SUBSTRING(s2.text,statement_start_offset / 2+1 , ( (CASE WHEN statement_end_offset = -1 THEN (LEN(CONVERT(nvarchar(max),s2.text)) * 2) ELSE statement_end_offset END) - statement_start_offset) / 2+1)) AS sql_statement, execution_count, plan_generation_num, last_execution_time, total_worker_time, last_worker_time, min_worker_time, max_worker_time, total_physical_reads

syntax error in CROSS APPLY

ぐ巨炮叔叔 提交于 2019-12-12 08:22:41
问题 I'm trying to run a simple query to find the queries with the highest average CPU time. The code is literally copy-pasted from here: SELECT TOP 5 total_worker_time/execution_count AS [Avg CPU Time], SUBSTRING(st.text, (qs.statement_start_offset/2)+1, ((CASE qs.statement_end_offset WHEN -1 THEN DATALENGTH(st.text) ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) + 1) AS statement_text FROM sys.dm_exec_query_stats AS qs CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st ORDER

How to Select from a variable?

社会主义新天地 提交于 2019-12-10 11:59:03
问题 My helper function for executing a DMV query: Function DMV_Query($DMV_Query) { ## Prepare the connection string based on information provided $connectionString = "Provider=msolap;Data Source=$AS_Server;Initial Catalog=$CUBE;" ## Connect to the data source and open $connection = New-Object System.Data.OleDb.OleDbConnection $connectionString $command = New-Object System.Data.OleDb.OleDbCommand $command.Connection = $connection $command.CommandText = $DMV_Query $connection.Open() ## Fetch the

25-SQLServer中的DMV和DMF的使用

醉酒当歌 提交于 2019-12-05 01:46:22
一、总结 1、什么事DMV和DMF DMV(Dynamic Management View):动态管理视图 DMF(Dynamic Management Function):动态管理函数 二、操作步骤 1.查看当前正在执行的SQL select r.start_time,r.status,r.command,db_name(r.database_id) as dbname,r.cpu_time,qt.text from sys.dm_exec_requests r cross apply sys.dm_exec_sql_text(r.sql_handle) qt 来源: https://www.cnblogs.com/jialanyu/p/11895555.html

syntax error in CROSS APPLY

♀尐吖头ヾ 提交于 2019-12-04 02:29:10
I'm trying to run a simple query to find the queries with the highest average CPU time. The code is literally copy-pasted from here : SELECT TOP 5 total_worker_time/execution_count AS [Avg CPU Time], SUBSTRING(st.text, (qs.statement_start_offset/2)+1, ((CASE qs.statement_end_offset WHEN -1 THEN DATALENGTH(st.text) ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) + 1) AS statement_text FROM sys.dm_exec_query_stats AS qs CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st ORDER BY total_worker_time/execution_count DESC; Problem is, SQL Server is complaining about a syntax error

Check if SQL object is referenced by any other SQL objects

拟墨画扇 提交于 2019-12-02 10:02:20
I was just reading this SO thread and had a question for @Mack regarding whether there is a way to check if a SQL object is referenced by any other SQL objects. He (@Mack) used T-SQL and DMVs to accomplish something similar in his answer. Is this possible, if so how? I would have posted this as a comment, but I don't have sufficient reputation yet... You can, but not with a DMV instead you'll need a related dynamic management function (DMF) dm_sql_referencing_entities (more info here ). Here is the code: SELECT referencing_schema_name , referencing_entity_name FROM sys.dm_sql_referencing