我需要查找并计算数据库中表上的所有索引,是否有任何内置 SP 或者我需要为其编写一些自定义 SP。
Select COUNT(1) from sys.indexes WHERE TYPE > 0 AND OBJECTPROPERTY(object_id,'IsSystemTable')=0
我为表名称添加了一个字段,以获取每个表启用和禁用的索引计数。这些数字与我手动检查时看到的相符。
另外,我推荐 Dave Pinal 的这篇文章 [https://blog.sqlauthority.com/2011/01/04/sql-server-2008-unused-index-script-download/]
Select object_name(object_id), /*give me the table name*/
count(*) /*count of all the indexes*/
from sys.indexes WHERE TYPE > 0
AND OBJECTPROPERTY(object_id,'IsSystemTable')=0
group by object_name(object_id)
having count(*) > 10
/*more than 10 is bad for performance*/
order by 2 desc
[1]: https://blog.sqlauthority.com/2011/01/04/sql-server-2008-unused-index-script-download/