察看数据库索引使用情况

使用下面的语句可以查看需要建立那些丢失的索引。

SELECT * FROM sys.dm_db_missing_index_details 

 

使用下面的语句可以查看数据中每个表的索引的使用情况,这尤其对于发现索引设计不合理的表非常有用。

SELECT OBJECT_NAME(object_id,database_id),* FROM sys.dm_db_index_usage_stats

 

SELECT 
    table_name=OBJECT_NAME(object_id,database_id),
    index_name=(select name from sys.indexes as b where b.object_id=a.object_id and b.index_id=a.index_id),
    row_count=(select SUM (row_count) from sys.dm_db_partition_stats as b where b.object_id=a.object_id and b.index_id=a.index_id),
    page_count=(select SUM (used_page_count) from sys.dm_db_partition_stats as b where b.object_id=a.object_id and b.index_id=a.index_id),
    * 
FROM sys.dm_db_index_usage_stats as a

 

posted @ 2010-03-16 22:46  昝昝  阅读(229)  评论(0编辑  收藏  举报