<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Indexes on SQL Server Scripts</title><link>https://www.sqlserver70.com/tags/indexes/</link><description>Recent content in Indexes on SQL Server Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>SQLServer70.com</copyright><lastBuildDate>Fri, 03 Apr 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.sqlserver70.com/tags/indexes/index.xml" rel="self" type="application/rss+xml"/><item><title>SQL Server Index Fragmentation: dm_db_index_physical_stats</title><link>https://www.sqlserver70.com/post/sql-server-index-fragmentation-sys-dm-db-index-physical-stats/</link><pubDate>Fri, 03 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-index-fragmentation-sys-dm-db-index-physical-stats/</guid><description>
&lt;h2 id="report-index-fragmentation-across-all-tables-in-sql-server"&gt;Report Index Fragmentation Across All Tables in SQL Server&lt;/h2&gt;
&lt;p&gt;This script queries &lt;code&gt;sys.dm_db_index_physical_stats&lt;/code&gt; to report external and internal fragmentation for every index in the current database, filtering to indexes with significant fragmentation and enough pages to make maintenance worthwhile.&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;Index fragmentation is one of the most common causes of gradually degrading query performance in SQL Server. As rows are inserted, updated, and deleted, index pages become out of order (external fragmentation) and partially empty (internal fragmentation). Both conditions force SQL Server to read more pages than necessary to satisfy a query. The &lt;code&gt;sys.dm_db_index_physical_stats&lt;/code&gt; dynamic management function scans index structures and reports fragmentation levels, giving DBAs the data needed to decide which indexes should be rebuilt and which should be reorganized. This script, adapted from the DBA-Scripts collection by Bulent Gucuk, runs against all tables in the current database and filters the output to actionable results.&lt;/p&gt;</description></item><item><title>SQL Server Unused Indexes: sys.dm_db_index_usage_stats</title><link>https://www.sqlserver70.com/post/sql-server-unused-indexes-sys-dm-db-index-usage-stats/</link><pubDate>Wed, 01 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-unused-indexes-sys-dm-db-index-usage-stats/</guid><description>
&lt;h2 id="find-unused-nonclustered-indexes-in-sql-server"&gt;Find Unused Nonclustered Indexes in SQL Server&lt;/h2&gt;
&lt;p&gt;This script queries &lt;code&gt;sys.dm_db_index_usage_stats&lt;/code&gt; to identify nonclustered indexes that have never been used by any read operation since the last SQL Server restart, yet still carry write overhead with every INSERT, UPDATE, and DELETE on the table.&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;Every nonclustered index in SQL Server has a cost: each time a row is inserted, updated, or deleted in the base table, SQL Server must also update every nonclustered index on that table. If an index is never used by the query optimizer — no seeks, scans, or lookups — it is pure overhead with no benefit. Over time, databases accumulate these unused indexes through abandoned development, changed application query patterns, or indexes added by automated tools without follow-up review. This script, from the DBA-Scripts collection by Bulent Gucuk, reads &lt;code&gt;sys.dm_db_index_usage_stats&lt;/code&gt; to expose every nonclustered index with zero read activity since the last server restart, and generates the DROP INDEX statement for each one.&lt;/p&gt;</description></item></channel></rss>