question

Chitra avatar image
Chitra asked

Rebuild index in Maintenance Plan

Do I need to rebuild index in maintenance plan if the following query gives null values:

http://www.sqlskills.com/BLOGS/PAUL/post/Indexes-From-Every-Angle-How-can-you-tell-if-an-index-is-being-used.aspx

                    
SELECT object_name(b.object_id) as obj_name, b.name as index_name, a.*                    
FROM sys.dm_db_index_usage_stats a                    
right outer join sys.indexes b on a.object_id = b.object_id                     
      and a.index_id = b.index_id and a.database_id = 5                    
where b.object_id > 100                    
order by user_seeks + user_scans                     

Regards

Chitra

indexesmaintenance-plans
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Håkan Winther avatar image
Håkan Winther answered
First of all, You don't need to rebuild indexes that doesn't have fragmentation, but this query doesn't tell you if the index is fragmented or not. You should replace `dm_db_index_usage_stats` with `dm_db_index_physical_stats` to get the fragmentation stats. Second, the DMW:s will be cleared when the instance is restarted etc, and that means that your indexes that hasn't been used after the restart may have been used before and might be used later on. (I know, it's an old question and you probably found the answer elsewhere, but... someone else might benefit from this answer)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.