﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Rabie Harriga  / Unused Indexes in your databases / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 09:59:13 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>Why used Union all, if run query after Union all separately it gives 0 rows in result. However only some additional clauses are in where clause of query after Union all. Cannot it be done in a single query without using Union all. Please explain</description><pubDate>Sat, 30 Mar 2013 06:25:16 GMT</pubDate><dc:creator>swatmadan.siet</dc:creator></item><item><title>RE: Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>Thank you.  That took care of my problem.</description><pubDate>Tue, 23 Aug 2011 09:23:13 GMT</pubDate><dc:creator>randal.schmidt</dc:creator></item><item><title>RE: Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>@Randall: Understand that this is using the sys.sysindexes view that may not be supported in future versions.[code="sql"]SELECT	LEFT(OBJECT_NAME (i.id), 50)	AS TableName,	LEFT(ISNULL(i.name,'HEAP'), 50)	AS IndexName,	CASE WHEN u.object_id IS NULL THEN 'No Data' ELSE 'No Usage' END AS Determination,	i.dpages	AS PagesUsed,	CONVERT(DECIMAL(8,2), i.dpages / 128.0) AS MBUsedFROM		sys.objects o	JOIN	sys.sysindexes i	ON	i.id = o.object_id	LEFT JOIN sys.dm_db_index_usage_stats u	ON		i.indid = u.index_id		AND	u.object_id = i.idWHERE		o.type = 'U'			-- Exclude system tables.	AND	i.name IS NOT NULL		-- Exclude heaps	AND	i.name NOT LIKE '_WA_Sys%'	-- Exclude statistics	AND	(	u.object_id IS NULL	-- Either no usage stats, or...		OR	(	u.user_seeks = 0	-- all usage stats are zero.			AND	u.user_scans = 0			AND	u.user_lookups = 0			)		)ORDER BY i.dpages DESC[/code]</description><pubDate>Tue, 23 Aug 2011 09:19:59 GMT</pubDate><dc:creator>fahey.jonathan</dc:creator></item><item><title>RE: Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>I am getting an error when I add that in (invalid column name dpages).  Can you post the complete SQL?</description><pubDate>Tue, 23 Aug 2011 08:57:06 GMT</pubDate><dc:creator>randal.schmidt</dc:creator></item><item><title>RE: Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>It is also helpful to know how much space is used by the index.  Here is how I did that:[code="sql"]CONVERT(DECIMAL(8,2), i.dpages / 128.0) AS MBUsed[/code]EDIT: I should note that I used sys.sysindexes rather than sys.indexes.  However, sys.sysindexes may not be supported in future versions of SQL Server.</description><pubDate>Tue, 23 Aug 2011 08:41:55 GMT</pubDate><dc:creator>fahey.jonathan</dc:creator></item><item><title>RE: Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>U can remove identity and unique keys from select by addingand i.is_primary_key = 0 and i.is_unique = 0 to both where clauses</description><pubDate>Thu, 17 Mar 2011 06:42:24 GMT</pubDate><dc:creator>Jaroslav Pfauser</dc:creator></item><item><title>RE: Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>The revised script works, but returns lots of duplicates, and also includes primary/unique key indexes (it doesn't matter if an index is 'used' if it's there to enforce integrity).</description><pubDate>Thu, 17 Mar 2011 04:35:03 GMT</pubDate><dc:creator>Toreador</dc:creator></item><item><title>RE: Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>i'am sorry, it is just one error of copy/past the good script is:/*Author: rabie harrigaVersion:SQL 2005, 2008, 2008 R2Decription:This Script allows you to determine the list of unused indexes in your databases*/select object_name (i.object_id) as NomTable,isnull( i.name,'HEAP') as IndexName from sys.objects o inner join sys.indexes iON i.[object_id] = o.[object_id] left joinsys.dm_db_index_usage_stats s on i.index_id = s.index_id and s.object_id = i.object_idwhere object_name (o.object_id) is not nulland object_name (s.object_id) is nullAND o.[type] = 'U'and isnull( i.name,'HEAP') &amp;lt;&amp;gt;'HEAP'union allselect object_name (i.object_id) as NomTable,isnull( i.name,'HEAP') as IndexName from sys.objects o inner join sys.indexes iON i.[object_id] = o.[object_id] left joinsys.dm_db_index_usage_stats s on i.index_id = s.index_id and s.object_id = i.object_idwhere user_seeks= 0and   user_scans=0and   user_lookups= 0AND o.[type] = 'U'and isnull( i.name,'HEAP') &amp;lt;&amp;gt;'HEAP'order by NomTable asc</description><pubDate>Thu, 24 Feb 2011 05:58:37 GMT</pubDate><dc:creator>harriga.rabie-1008938</dc:creator></item><item><title>RE: Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>There are several errors in the code as presented. Please clean your code before you publish it.</description><pubDate>Wed, 23 Feb 2011 13:41:54 GMT</pubDate><dc:creator>Dave Vroman</dc:creator></item><item><title>RE: Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>I have a question.Does this statistics persist after a SQL Server service restart? or server reboot etc.</description><pubDate>Wed, 23 Feb 2011 09:08:31 GMT</pubDate><dc:creator>mgigani-696113</dc:creator></item><item><title>RE: Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>select object_name (i.object_id) as NomTable,isnull( i.name,'HEAP') as IndexName from sys.objects o inner join sys.indexes iON i.[object_id] = o.[object_id] left joinsys.dm_db_index_usage_stats s on i.index_id = s.index_id and s.object_id = i.object_idwhere object_name (o.object_id) is not nulland object_name (s.object_id) is nullAND o.[type] = 'U'and isnull( i.name,'HEAP') &amp;lt;&amp;gt;'HEAP'union all/*part 2 : indexes in sys.dm_db_index_usage_stats with •	user_seeks= 0•	user_scans=0•	user_lookups= 0*/select object_name (i.object_id) as NomTable,isnull( i.name,'HEAP') as IndexName from sys.objects o inner join sys.indexes iON i.[object_id] = o.[object_id] left joinsys.dm_db_index_usage_stats s on i.index_id = s.index_id and s.object_id = i.object_idwhere user_seeks= 0and   user_scans=0and   user_lookups= 0AND o.[type] = 'U'and isnull( i.name,'HEAP') &amp;lt;&amp;gt;'HEAP'order by NomTable asc</description><pubDate>Wed, 23 Feb 2011 08:28:33 GMT</pubDate><dc:creator>harriga.rabie-1008938</dc:creator></item><item><title>RE: Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>Double Order By and Where clauses.  Even if I comment one of the doubles out for each, the script still fails with errors:Msg 207, Level 16, State 1, Line 34Invalid column name 'user_scans'.Msg 207, Level 16, State 1, Line 34Invalid column name 'user_lookups'.Msg 4104, Level 16, State 1, Line 34The multi-part identifier "s.object_id" could not be bound.</description><pubDate>Wed, 23 Feb 2011 08:02:49 GMT</pubDate><dc:creator>bustell</dc:creator></item><item><title>RE: Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>Also two where clauses.  Fixed the two duplicates, but still have a page of error messages.</description><pubDate>Wed, 23 Feb 2011 07:43:22 GMT</pubDate><dc:creator>gitmo</dc:creator></item><item><title>RE: Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>There are two ORDER BY clauses in a row.  The script does not work.</description><pubDate>Wed, 23 Feb 2011 06:55:50 GMT</pubDate><dc:creator>randal.schmidt</dc:creator></item><item><title>Unused Indexes in your databases</title><link>http://www.sqlservercentral.com/Forums/Topic1068035-2908-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/Indexing/72486/"&gt;Unused Indexes in your databases&lt;/A&gt;[/B]</description><pubDate>Tue, 22 Feb 2011 20:51:17 GMT</pubDate><dc:creator>harriga.rabie-1008938</dc:creator></item></channel></rss>