<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SQL Server Monitoring on SQL Server Scripts</title><link>https://www.sqlserver70.com/series/sql-server-monitoring/</link><description>Recent content in SQL Server Monitoring on SQL Server Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>SQLServer70.com</copyright><lastBuildDate>Sun, 24 May 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.sqlserver70.com/series/sql-server-monitoring/index.xml" rel="self" type="application/rss+xml"/><item><title>SQL Server Get Table and Index Storage Size Report Script</title><link>https://www.sqlserver70.com/post/sql-server-get-table-and-index-storage-size/</link><pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-get-table-and-index-storage-size/</guid><description>
&lt;p&gt;Knowing how much space each table and each index consumes is the foundation of capacity planning, archive policy, and index cleanup decisions on any SQL Server instance. This T-SQL script reads the partition-level storage statistics out of &lt;code&gt;sys.dm_db_partition_stats&lt;/code&gt; and reports the size of every index — clustered, non-clustered, and the heap row that represents the table itself — in both kilobytes and megabytes, schema- and table-named for easy review.&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;Backup windows that creep, restore tests that get skipped, archive policies that never get written — all three trace back to the same missing input: a current, per-object inventory of bytes-on-disk. &lt;code&gt;sys.dm_db_partition_stats&lt;/code&gt; carries the page counts that answer the question; &lt;code&gt;sp_spaceused&lt;/code&gt; only aggregates at the table or database level and loses the index-by-index detail this kind of capacity work needs. The query below converts those page counts to KB and MB for every index and every table in the current database, ready to paste into the next capacity-planning spreadsheet.&lt;/p&gt;</description></item><item><title>SQL Server Database File Space Usage Report</title><link>https://www.sqlserver70.com/post/sql-server-database-file-space-usage-report/</link><pubDate>Sun, 17 May 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-database-file-space-usage-report/</guid><description>
&lt;p&gt;Running out of space inside a data or log file halts SQL Server transactions immediately — and discovering that a volume is full only after an outage is too late. This script queries &lt;code&gt;sys.master_files&lt;/code&gt; and &lt;code&gt;sys.dm_os_volume_stats&lt;/code&gt; across every online database on the instance to report each file's allocated size, space actually written, free space inside the file, percent used, autogrowth configuration, and the amount of free space remaining on the underlying disk volume.&lt;/p&gt;</description></item><item><title>SQL Server TempDB Usage and Contention Report</title><link>https://www.sqlserver70.com/post/sql-server-tempdb-usage-contention-report/</link><pubDate>Fri, 17 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-tempdb-usage-contention-report/</guid><description>
&lt;p&gt;TempDB is a shared system database used by every session in SQL Server. When TempDB space grows or performance slows, it can be difficult to know which sessions are responsible. This script queries &lt;code&gt;sys.dm_db_session_space_usage&lt;/code&gt; to show a clear breakdown of TempDB consumption per session, including the current SQL statement being run.&lt;/p&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&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;p&gt;TempDB is used for temporary tables, table variables, sort operations, hash joins, cursors, and row versioning. Any session can allocate TempDB space, and heavy use can cause disk pressure or contention on allocation pages (GAM, SGAM, PFS).&lt;/p&gt;</description></item><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 Database Size Report for All Databases</title><link>https://www.sqlserver70.com/post/sql-server-database-size-report-all-databases/</link><pubDate>Thu, 02 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-database-size-report-all-databases/</guid><description>
&lt;h2 id="report-database-size-in-mb-and-gb-for-all-sql-server-databases"&gt;Report Database Size in MB and GB for All SQL Server Databases&lt;/h2&gt;
&lt;p&gt;This script queries &lt;code&gt;sys.master_files&lt;/code&gt; and &lt;code&gt;sys.databases&lt;/code&gt; to report the total allocated size in megabytes and gigabytes for every user database on the SQL Server instance, sorted by largest database first.&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;Knowing how large each database is — and tracking how that size changes over time — is a core part of SQL Server capacity planning. Running out of disk space is one of the most disruptive events a DBA can face: it halts log backups, prevents transactions from committing, and can take databases offline. This script, adapted from the DBA-Scripts collection by Bulent Gucuk, reads allocated file sizes from &lt;code&gt;sys.master_files&lt;/code&gt; and joins to &lt;code&gt;sys.databases&lt;/code&gt; to produce a single server-wide size report. It runs from the master database, requires no cross-database queries, and takes milliseconds to execute — making it safe to run at any time, including during a production incident.&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;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&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;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><item><title>Generate SQL Server Space Usage Commands for All User Tables</title><link>https://www.sqlserver70.com/post/sql-server-generate-space-usage-commands-for-all-tables/</link><pubDate>Thu, 07 Aug 2025 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-generate-space-usage-commands-for-all-tables/</guid><description>
&lt;h2 id="generate-sql-server-space-usage-commands-for-all-user-tables"&gt;Generate SQL Server Space Usage Commands for All User Tables&lt;/h2&gt;
&lt;p&gt;Managing database storage is a critical aspect of SQL Server administration. Understanding how much space each table consumes helps database administrators make informed decisions about maintenance, archiving, and performance optimization. This article explores a powerful T-SQL script that automatically generates space usage commands for all user tables in your database.
&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;/p&gt;
&lt;h2 id="the-sql-server-code"&gt;The SQL Server Code&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sql" data-lang="sql"&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;1&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;select&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;sp_spaceused &amp;#39;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;go&amp;#39;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sysobjects&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;where&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;U&amp;#39;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;order&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;by&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;This T-SQL query serves as a time-saving utility for database administrators who need to quickly assess the space usage of all user tables in a SQL Server database. Instead of manually typing &lt;code&gt;sp_spaceused&lt;/code&gt; commands for each table, this script automatically generates the complete set of commands ready for execution.&lt;/p&gt;</description></item><item><title>SQL Server Table Row Count Report: Complete T-SQL Script</title><link>https://www.sqlserver70.com/post/sql-server-database-table-row-count-report-script/</link><pubDate>Sat, 02 Aug 2025 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-database-table-row-count-report-script/</guid><description>
&lt;h2 id="sql-server-database-table-row-count-report-script---complete-guide"&gt;SQL Server Database Table Row Count Report Script - Complete Guide&lt;/h2&gt;
&lt;p&gt;Database administrators frequently need to monitor table sizes and row counts across their SQL Server databases. This comprehensive guide explores a powerful T-SQL script that generates detailed table row count reports using cursor-based iteration and system table queries.
&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;/p&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;The &amp;quot;Run Space Report&amp;quot; script serves as a database monitoring tool that captures essential table statistics including server name, execution timestamp, database name, table name, and total row counts. This information proves invaluable for capacity planning, performance optimization, and database maintenance activities.&lt;/p&gt;</description></item></channel></rss>