首页 > 代码库 > SQL SERVER查看索引使用情况

SQL SERVER查看索引使用情况

SELECT DISTINCT
        DB_NAME() AS N‘db_name‘ ,
        E.name AS N‘schema_name‘ ,
        OBJECT_NAME(a.object_id) AS N‘table_name‘ ,
        b.name N‘index_name‘ ,
        user_seeks N‘seek‘ ,
        user_scans N‘scan‘ ,
        last_user_seek ,
        last_user_scan ,
        rows
FROM    sys.dm_db_index_usage_stats a
        INNER JOIN sys.indexes b ON a.index_id = b.index_id
                                   AND a.object_id = b.object_id
        INNER JOIN sysindexes c ON c.id = b.object_id
        INNER JOIN sys.objects D ON D.object_id = b.object_id
        INNER JOIN sys.schemas E ON D.schema_id = E.schema_id
WHERE   E.name = ‘Finance‘ --架构名
        --AND OBJECT_NAME(a.object_id) = ‘CostCenter‘--表名
        AND b.name = ‘IX_CostCategory_CnName‘ --索引名称
        AND rows <> 0;

 

技术分享

SQL SERVER查看索引使用情况