Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Low use Indexes

Posted on 2011-02-25
3
Medium Priority
?
247 Views
Last Modified: 2012-05-11
I need to compile statictics info on useage of all indexes to see which are not being used and then delete them from the system. How can I do that.

I need to monitor index usage for 2 weeks

Using SQL Server 2008 R2
0
Comment
Question by:tantradude
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 34984030
select * from sys.dm_db_index_usage_stats
0
 
LVL 41

Expert Comment

by:Sharath
ID: 34984120
To find unused indexes:
DECLARE  @dbid INT
SELECT @dbid = DB_ID(DB_NAME())
SELECT   OBJECTNAME = OBJECT_NAME(I.OBJECT_ID),
            INDEXNAME = I.NAME,
            I.INDEX_ID
    FROM     SYS.INDEXES I
            JOIN SYS.OBJECTS O
            ON I.OBJECT_ID = O.OBJECT_ID
    WHERE    OBJECTPROPERTY(O.OBJECT_ID,'IsUserTable') = 1
        AND I.INDEX_ID NOT IN (
    SELECT S.INDEX_ID
        FROM   SYS.DM_DB_INDEX_USAGE_STATS S
        WHERE  S.OBJECT_ID = I.OBJECT_ID
            AND I.INDEX_ID = S.INDEX_ID
            AND DATABASE_ID = @dbid)
    ORDER BY OBJECTNAME,
            I.INDEX_ID,
            INDEXNAME ASC

Open in new window

0
 
LVL 15

Accepted Solution

by:
Aaron Shilo earned 2000 total points
ID: 34986167
this will list unused indexes:

the condition  (user_seeks + user_scans + user_lookups ) = 0
will retrive indexes with no seeks scans or lookups

declare @dbid int
select @dbid = db_id()
select objectname=object_name(s.object_id), s.object_id
      , indexname=i.name, i.index_id
      , user_seeks, user_scans, user_lookups, user_updates
from sys.dm_db_index_usage_stats s,
      sys.indexes i
where database_id = @dbid
and objectproperty(s.object_id,'IsUserTable') = 1
and i.object_id = s.object_id
and i.index_id = s.index_id
and  (user_seeks + user_scans + user_lookups) = 0
order by (user_seeks + user_scans + user_lookups) asc
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question