Solved

Low use Indexes

Posted on 2011-02-25
3
235 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
3 Comments
 
LVL 60

Expert Comment

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

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 500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now