Index使用状况

  • SQL语句实现查询Index使用状况

    要查询SQL Server中表的索引使用状况,可以使用以下SQL语句:,,``sql,SELECT , OBJECT_NAME(i.object_id) AS TableName,, i.name AS IndexName,, i.index_id,, COUNT(s.status) AS TotalStatus,, SUM(CASE WHEN s.status = 0 THEN 1 ELSE 0 END) AS OptimalStatus,, SUM(CASE WHEN s.status = 1 THEN 1 ELSE 0 END) AS SuboptimalStatus,, SUM(CASE WHEN s.status = 2 THEN 1 ELSE 0 END) AS DeferredStatus,FROM , sys.dm_db_index_usage_stats s,JOIN , sys.indexes i ON s.object_id = i.object_id AND s.index_id = i.index_id,GROUP BY , i.object_id, i.name, i.index_id,ORDER BY , TableName, TotalStatus DESC;,``,,这个SQL语句会返回每个表的索引名称、索引ID以及各种状态的数量(最优、次优和延迟)。

    2024-05-21
    0121
免备案 高防CDN 无视CC/DDOS攻击 限时秒杀,10元即可体验  (专业解决各类攻击)>>点击进入