<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sys.dm_exec_sql_text on SQL Server Scripts</title><link>https://www.sqlserver70.com/tags/sys.dm_exec_sql_text/</link><description>Recent content in Sys.dm_exec_sql_text on SQL Server Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>SQLServer70.com</copyright><lastBuildDate>Sun, 12 Apr 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.sqlserver70.com/tags/sys.dm_exec_sql_text/index.xml" rel="self" type="application/rss+xml"/><item><title>SQL Server Long-Running Queries: Find Active Sessions</title><link>https://www.sqlserver70.com/post/sql-server-find-long-running-queries/</link><pubDate>Sun, 12 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-find-long-running-queries/</guid><description>
&lt;h2 id="find-active-long-running-queries-in-sql-server"&gt;Find Active Long-Running Queries in SQL Server&lt;/h2&gt;
&lt;p&gt;This script queries &lt;code&gt;sys.dm_exec_requests&lt;/code&gt; and &lt;code&gt;sys.dm_exec_sql_text&lt;/code&gt; to show all currently executing queries on the SQL Server instance, sorted by how long they have been running, along with CPU time, I/O activity, blocking status, and wait type information.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;A query that normally completes in seconds but has been running for many minutes is one of the most common performance problems a DBA investigates. The cause could be blocking from another session, a missing index, parameter sniffing producing a bad plan, or a sudden increase in data volume. The first step in diagnosing the problem is knowing what is running right now. SQL Server exposes this through the &lt;code&gt;sys.dm_exec_requests&lt;/code&gt; dynamic management view, which holds one row for every active request currently executing on the instance. Combined with &lt;code&gt;sys.dm_exec_sql_text&lt;/code&gt;, which returns the actual T-SQL text for a given SQL handle, this query gives you immediate visibility into what every session is doing, how long it has been running, and whether it is waiting on something.&lt;/p&gt;</description></item><item><title>SQL Server Top Queries by CPU and IO: dm_exec_query_stats</title><link>https://www.sqlserver70.com/post/sql-server-top-queries-by-cpu-and-io-sys-dm-exec-query-stats/</link><pubDate>Sat, 04 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-top-queries-by-cpu-and-io-sys-dm-exec-query-stats/</guid><description>
&lt;h2 id="find-the-top-cpu-and-io-consuming-queries-in-sql-server"&gt;Find the Top CPU and IO Consuming Queries in SQL Server&lt;/h2&gt;
&lt;p&gt;This script queries &lt;code&gt;sys.dm_exec_query_stats&lt;/code&gt; to identify the most resource-intensive queries currently cached in the plan cache, showing logical reads, writes, CPU time, and elapsed time — with the full query text and execution plan for each.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;When a SQL Server instance is under CPU or I/O pressure, the first diagnostic step is finding which queries are responsible. &lt;code&gt;sys.dm_exec_query_stats&lt;/code&gt; holds cumulative execution statistics for every query plan currently in the plan cache. Sorted by total logical reads or total CPU time, it quickly surfaces the queries doing the most work. This script, adapted from the DBA-Scripts collection by Bulent Gucuk, combines &lt;code&gt;sys.dm_exec_query_stats&lt;/code&gt; with &lt;code&gt;sys.dm_exec_sql_text&lt;/code&gt; and &lt;code&gt;sys.dm_exec_query_plan&lt;/code&gt; to return the query text and execution plan alongside the performance metrics — giving you everything needed to begin tuning in a single result set.&lt;/p&gt;</description></item><item><title>SQL Server Blocking Detection: Find Blocked Sessions</title><link>https://www.sqlserver70.com/post/sql-server-blocking-detection-find-blocked-sessions/</link><pubDate>Sun, 01 Mar 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-blocking-detection-find-blocked-sessions/</guid><description>
&lt;p&gt;Blocking in SQL Server occurs when one session holds a lock that another session needs, causing the second session to wait. This T-SQL script queries the dynamic management views to show all currently blocked sessions, the blocking session, wait type, wait duration, and the SQL text involved.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;When users report slow queries or application timeouts, blocking is a common cause. SQL Server does not alert you to blocking by default — you must query the DMVs to see what is happening in real time.&lt;/p&gt;</description></item></channel></rss>