<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SQL Server Index - MSSQL Query</title>
	<atom:link href="https://mssqlquery.com/tag/sql-server-index/feed" rel="self" type="application/rss+xml" />
	<link>https://mssqlquery.com</link>
	<description>MSSQL and TSQL Programming and TSQL Examples</description>
	<lastBuildDate>Fri, 07 Apr 2023 19:01:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.3.2</generator>

<image>
	<url>https://mssqlquery.com/wp-content/uploads/2023/06/cropped-mssql-query-icon-32x32.png</url>
	<title>SQL Server Index - MSSQL Query</title>
	<link>https://mssqlquery.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Detecting Unused Indexes in SQL Server</title>
		<link>https://mssqlquery.com/detecting-unused-indexes-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Fri, 25 Nov 2022 21:28:26 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Index]]></category>
		<category><![CDATA[Unused Indexes in SQL Server]]></category>
		<category><![CDATA[Unused Indexes SQL Server]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=1221</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will try to give information about detecting unused Indexes in SQL Server. In SQL Server, in some cases, you may want to detect unused Indexes. You can easily do this using the code below. SELECT o.name AS ObjectName, i.name AS IndexName, i.index_id AS IndexID,&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/detecting-unused-indexes-in-sql-server">Detecting Unused Indexes in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will try to give information about detecting unused Indexes in SQL Server.</p>
<p>In SQL Server, in some cases, you may want to detect unused Indexes.</p>
<p>You can easily do this using the code below.</p>
<pre class="line-numbers"><code class="language-sql">SELECT o.name AS ObjectName,
       i.name AS IndexName,
       i.index_id AS IndexID,
       dm_ius.user_seeks AS UserSeek,
       dm_ius.user_scans AS UserScans,
       dm_ius.user_lookups AS UserLookups,
       dm_ius.user_updates AS UserUpdates,
       p.TableRows,
       'DROP INDEX ' + QUOTENAME(i.name) + ' ON ' + QUOTENAME(s.name) + '.' + QUOTENAME(OBJECT_NAME(dm_ius.object_id)) AS 'drop statement'
FROM sys.dm_db_index_usage_stats dm_ius
    INNER JOIN sys.indexes i
        ON i.index_id = dm_ius.index_id
           AND dm_ius.object_id = i.object_id
    INNER JOIN sys.objects o
        ON dm_ius.object_id = o.object_id
    INNER JOIN sys.schemas s
        ON o.schema_id = s.schema_id
    INNER JOIN
    (
        SELECT SUM(p.rows) TableRows,
               p.index_id,
               p.object_id
        FROM sys.partitions p
        GROUP BY p.index_id,
                 p.object_id
    ) p
        ON p.index_id = dm_ius.index_id
           AND dm_ius.object_id = p.object_id
WHERE OBJECTPROPERTY(dm_ius.object_id, 'IsUserTable') = 1
      AND dm_ius.database_id = DB_ID()
      AND i.type_desc = 'nonclustered'
      AND i.is_primary_key = 0
      AND i.is_unique_constraint = 0
ORDER BY (dm_ius.user_seeks + dm_ius.user_scans + dm_ius.user_lookups) ASC;
GO</code></pre>
<p>When you run the above code, you will see a result similar to the one below.</p>
<p><img decoding="async" fetchpriority="high" class="alignnone wp-image-1223 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/11/detecting-unused-indexes-in-sql-server-1.jpg" alt="Detecting Unused Indexes in SQL Server" width="700" height="390" srcset="https://mssqlquery.com/wp-content/uploads/2022/11/detecting-unused-indexes-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/11/detecting-unused-indexes-in-sql-server-1-300x167.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, we have detected unused indexes.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 113</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/detecting-unused-indexes-in-sql-server">Detecting Unused Indexes in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Finding Fragmentation Rates of Indexes in SQL Server</title>
		<link>https://mssqlquery.com/finding-fragmentation-rates-of-indexes-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Thu, 14 Apr 2022 19:55:51 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Rates of Indexes in SQL Server]]></category>
		<category><![CDATA[SQL Server Index]]></category>
		<category><![CDATA[TSQL Index Fragmentation]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=890</guid>

					<description><![CDATA[<p>Hello to everyone, In this article, I will try to give information about finding Fragmentation rates of Indexes in SQL Server. In SQL Server, in some cases, you may want to find the Fragmentation rates of Indexes. You can easily do this using the code below. SELECT ps.object_id, i.name AS&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/finding-fragmentation-rates-of-indexes-in-sql-server">Finding Fragmentation Rates of Indexes in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello to everyone,</p>
<p>In this article, I will try to give information about finding Fragmentation rates of Indexes in SQL Server.</p>
<p>In SQL Server, in some cases, you may want to find the Fragmentation rates of Indexes.</p>
<p>You can easily do this using the code below.</p>
<pre class="line-numbers"><code class="language-sql">SELECT ps.object_id,
       i.name AS IndexName,
       OBJECT_SCHEMA_NAME(ps.object_id) AS ObjectSchemaName,
       OBJECT_NAME(ps.object_id) AS ObjectName,
       ps.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'LIMITED') ps
    INNER JOIN sys.indexes i
        ON i.object_id = ps.object_id
           AND i.index_id = ps.index_id
WHERE avg_fragmentation_in_percent &gt; 5
      AND ps.index_id &gt; 0
ORDER BY avg_fragmentation_in_percent DESC;</code></pre>
<p>When you run the above code, you will see a result similar to the one below.</p>
<p><img decoding="async" class="alignnone wp-image-892 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/04/finding-fragmentation-rates-of-indexes-in-sql-server-1.jpg" alt="Finding Fragmentation Rates of Indexes in SQL Server" width="700" height="543" srcset="https://mssqlquery.com/wp-content/uploads/2022/04/finding-fragmentation-rates-of-indexes-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/04/finding-fragmentation-rates-of-indexes-in-sql-server-1-300x233.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As can be seen, the Fragmentation rates of the Indexes have been found.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 179</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/finding-fragmentation-rates-of-indexes-in-sql-server">Finding Fragmentation Rates of Indexes in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Listing Indexes Linked to Tables in SQL Server</title>
		<link>https://mssqlquery.com/listing-indexes-linked-to-tables-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Fri, 08 Apr 2022 19:01:47 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Listing Indexes SQL Server]]></category>
		<category><![CDATA[SQL Server Index]]></category>
		<category><![CDATA[TSQL Index]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=841</guid>

					<description><![CDATA[<p>Hello to everyone, In this article, I will try to give information about listing indexes linked to tables in SQL Server. In SQL Server, in some cases, you may want to list the indexes that are linked to the tables. You can easily do this using the code below. SELECT&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/listing-indexes-linked-to-tables-in-sql-server">Listing Indexes Linked to Tables in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello to everyone,</p>
<p>In this article, I will try to give information about listing indexes linked to tables in SQL Server.</p>
<p>In SQL Server, in some cases, you may want to list the indexes that are linked to the tables.</p>
<p>You can easily do this using the code below.</p>
<pre class="line-numbers"><code class="language-sql">SELECT QUOTENAME(t.name) AS [Table Name],
       QUOTENAME(i.name) AS [Index Name],
       i.is_primary_key AS [Is Auto-Incrementing],
       STUFF(REPLACE(REPLACE(
                     (
                         SELECT QUOTENAME(c.name) + CASE
                                                        WHEN ic.is_descending_key = 1 THEN
                                                            ' DESC'
                                                        ELSE
                                                            ''
                                                    END AS [data()]
                         FROM sys.index_columns AS ic
                             INNER JOIN sys.columns AS c
                                 ON ic.object_id = c.object_id
                                    AND ic.column_id = c.column_id
                         WHERE ic.object_id = i.object_id
                               AND ic.index_id = i.index_id
                               AND ic.is_included_column = 0
                         ORDER BY ic.key_ordinal
                         FOR XML PATH
                     ),
                     '&lt;row&gt;',
                     ', '
                            ),
                     '&lt;/row&gt;',
                     ''
                    ),
             1,
             2,
             ''
            ) AS [Index Field Information],
       STUFF(REPLACE(REPLACE(
                     (
                         SELECT QUOTENAME(c.name) AS [data()]
                         FROM sys.index_columns AS ic
                             INNER JOIN sys.columns AS c
                                 ON ic.object_id = c.object_id
                                    AND ic.column_id = c.column_id
                         WHERE ic.object_id = i.object_id
                               AND ic.index_id = i.index_id
                               AND ic.is_included_column = 1
                         ORDER BY ic.index_column_id
                         FOR XML PATH
                     ),
                     '&lt;row&gt;',
                     ', '
                            ),
                     '&lt;/row&gt;',
                     ''
                    ),
             1,
             2,
             ''
            ) AS [Index Include Information]
FROM sys.tables AS t
    INNER JOIN sys.indexes AS i
        ON t.object_id = i.object_id
    LEFT JOIN sys.dm_db_index_usage_stats AS u
        ON i.object_id = u.object_id
           AND i.index_id = u.index_id
WHERE t.is_ms_shipped = 0
      AND t.name LIKE '%'
      AND i.type &lt;&gt; 0
ORDER BY i.name;</code></pre>
<p>When you run the above code block, you will see the following result.</p>
<p><img decoding="async" class="alignnone wp-image-843 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/04/listing-indexes-linked-to-tables-in-sql-server-1.jpg" alt="Listing Indexes Linked to Tables in SQL Server" width="700" height="478" srcset="https://mssqlquery.com/wp-content/uploads/2022/04/listing-indexes-linked-to-tables-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/04/listing-indexes-linked-to-tables-in-sql-server-1-300x205.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, the indexes linked to the tables are listed.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 170</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/listing-indexes-linked-to-tables-in-sql-server">Listing Indexes Linked to Tables in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Finding Unused Index in SQL Server</title>
		<link>https://mssqlquery.com/finding-unused-index-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Sun, 27 Feb 2022 21:06:19 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Finding Unused Index]]></category>
		<category><![CDATA[SQL Server Index]]></category>
		<category><![CDATA[Unused Index in SQL Server]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=725</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will try to give information about finding Unused Index values in SQL Server. In SQL Server you may want to find unused Index values in some cases. You can easily do this by using the script below. SELECT TOP 25 o.name AS ObjectName, i.name&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/finding-unused-index-in-sql-server">Finding Unused Index in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will try to give information about finding Unused Index values in SQL Server.</p>
<p>In SQL Server you may want to find unused Index values in some cases.</p>
<p>You can easily do this by using the script below.</p>
<pre class="line-numbers"><code class="language-sql">SELECT TOP 25
       o.name AS ObjectName,
       i.name AS IndexName,
       i.index_id AS IndexID,
       dm_ius.user_seeks AS UserSeek,
       dm_ius.user_scans AS UserScans,
       dm_ius.user_lookups AS UserLookups,
       dm_ius.user_updates AS UserUpdates,
       p.TableRows,
       'DROP INDEX ' + QUOTENAME(i.name) + ' ON ' + QUOTENAME(s.name) + '.' + QUOTENAME(OBJECT_NAME(dm_ius.object_id)) AS 'drop statement'
FROM sys.dm_db_index_usage_stats dm_ius
    INNER JOIN sys.indexes i
        ON i.index_id = dm_ius.index_id
           AND dm_ius.object_id = i.object_id
    INNER JOIN sys.objects o
        ON dm_ius.object_id = o.object_id
    INNER JOIN sys.schemas s
        ON o.schema_id = s.schema_id
    INNER JOIN
    (
        SELECT SUM(p.rows) TableRows,
               p.index_id,
               p.object_id
        FROM sys.partitions p
        GROUP BY p.index_id,
                 p.object_id
    ) p
        ON p.index_id = dm_ius.index_id
           AND dm_ius.object_id = p.object_id
WHERE OBJECTPROPERTY(dm_ius.object_id, 'IsUserTable') = 1
      AND dm_ius.database_id = DB_ID()
      AND i.type_desc = 'nonclustered'
      AND i.is_primary_key = 0
      AND i.is_unique_constraint = 0
ORDER BY (dm_ius.user_seeks + dm_ius.user_scans + dm_ius.user_lookups) ASC;</code></pre>
<p><strong>Note:</strong> It goes without saying, please test all the script on your development server and after they pass your test, deploy them on production server.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 179</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/finding-unused-index-in-sql-server">Finding Unused Index in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Listing All Indexes in Database in SQL Server</title>
		<link>https://mssqlquery.com/listing-all-indexes-in-database-in-sql-server</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Sun, 23 Jan 2022 12:34:18 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[All Indexes in Database in SQL Server]]></category>
		<category><![CDATA[List All Index for SQL Server]]></category>
		<category><![CDATA[SQL Server Index]]></category>
		<guid isPermaLink="false">https://mssqlquery.com/?p=564</guid>

					<description><![CDATA[<p>Hello everyone, In this article, I will give information about listing all the indexes in the database in SQL Server. In SQL Server, in some cases, we may want all index values in the database to be listed. You can easily do this with the help of the code below.&#46;&#46;&#46;</p>
<p>The post <a href="https://mssqlquery.com/listing-all-indexes-in-database-in-sql-server">Listing All Indexes in Database in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>In this article, I will give information about listing all the indexes in the database in SQL Server.</p>
<p>In SQL Server, in some cases, we may want all index values in the database to be listed.</p>
<p>You can easily do this with the help of the code below.</p>
<pre class="line-numbers"><code class="language-sql">SELECT i.[name] AS index_name,
       SUBSTRING(column_names, 1, LEN(column_names) - 1) AS [columns],
       CASE
           WHEN i.[type] = 1 THEN
               'Clustered index'
           WHEN i.[type] = 2 THEN
               'Nonclustered unique index'
           WHEN i.[type] = 3 THEN
               'XML index'
           WHEN i.[type] = 4 THEN
               'Spatial index'
           WHEN i.[type] = 5 THEN
               'Clustered columnstore index'
           WHEN i.[type] = 6 THEN
               'Nonclustered columnstore index'
           WHEN i.[type] = 7 THEN
               'Nonclustered hash index'
       END AS index_type,
       CASE
           WHEN i.is_unique = 1 THEN
               'Unique'
           ELSE
               'Not unique'
       END AS [unique],
       SCHEMA_NAME(t.schema_id) + '.' + t.[name] AS table_view,
       CASE
           WHEN t.[type] = 'U' THEN
               'Table'
           WHEN t.[type] = 'V' THEN
               'View'
       END AS [object_type]
FROM sys.objects t
    INNER JOIN sys.indexes i
        ON t.object_id = i.object_id
    CROSS APPLY
(
    SELECT col.[name] + ', '
    FROM sys.index_columns ic
        INNER JOIN sys.columns col
            ON ic.object_id = col.object_id
               AND ic.column_id = col.column_id
    WHERE ic.object_id = t.object_id
          AND ic.index_id = i.index_id
    ORDER BY col.column_id
    FOR XML PATH('')
) D(column_names)
WHERE t.is_ms_shipped &lt;&gt; 1
      AND index_id &gt; 0
ORDER BY i.[name];</code></pre>
<p>When you run the code, you will get a result like the one below.</p>
<p><img decoding="async" loading="lazy" class="alignnone wp-image-566 size-full" src="https://mssqlquery.com/wp-content/uploads/2022/01/listing-all-indexes-in-database-in-sql-server-1.jpg" alt="Listing All Indexes in Database in SQL Server" width="700" height="441" srcset="https://mssqlquery.com/wp-content/uploads/2022/01/listing-all-indexes-in-database-in-sql-server-1.jpg 700w, https://mssqlquery.com/wp-content/uploads/2022/01/listing-all-indexes-in-database-in-sql-server-1-300x189.jpg 300w" sizes="(max-width: 700px) 100vw, 700px" /></p>
<p>As you can see, all index values are listed.</p>
<p>I ran the transaction on the Northwind database in order to be an example transaction. You can run it on the database you want.</p>
<p>Good luck to everyone in business and life.</p>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 292</span><span class='epvc-label'> Views</span></div><p>The post <a href="https://mssqlquery.com/listing-all-indexes-in-database-in-sql-server">Listing All Indexes in Database in SQL Server</a> first appeared on <a href="https://mssqlquery.com">MSSQL Query</a>.</p>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
