1. 程式人生 > >SQL SERVER查看索引使用情況

SQL SERVER查看索引使用情況

use can png log table schema ats _id sca

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查看索引使用情況