set nocount on go select DB_NAME() as db_name ,d.name as object_name ,e.rowcnt ,str(c.avg_total_user_cost*(c.user_scans+c.user_seeks),16,0) as total_user_cost --总成本 ,str(c.avg_total_user_cost,16,0) as avg_total_user_cost --平均成本 ,c.avg_user_impact --平均收益(%) --,c.user_scans --受益 的 scan 次数 ,c.user_seeks --受益 的 seek 次数 ,c.unique_compiles as compiles --涉及到该索引的 compile 次数 ,a.equality_columns,a.inequality_columns --,a.included_columns ,case when a.included_columns is not null then 'yes' else '' end as [has_include] ,d.name as object_name2 ,'CREATE INDEX [IX_' + d.name + '_' + replace(replace(replace(replace(isnull(a.equality_columns,a.inequality_columns),'[',''),']',''),',','_'),char(32),'') + ']' + ' ON ' + a.statement + ' ('+ case when a.equality_columns is not null then a.equality_columns else a.inequality_columns end + ')' + case when a.included_columns is not null then ' INCLUDE (' + a.included_columns + ')' else '' end as create_index_stmt --,str(c.avg_total_system_cost,16,0) as avg_total_system_cost,c.avg_system_impact --,c.system_scans,c.system_seeks --,c.last_user_scan,c.last_system_seek --,c.last_system_scan,c.last_system_seek from sys.dm_db_missing_index_details a inner join sys.dm_db_missing_index_groups b on b.index_handle=a.index_handle inner join sys.dm_db_missing_index_group_stats c on c.group_handle=b.index_group_handle inner join sys.objects d on d.object_id=a.object_id inner join sysindexes e on e.indid in (0,1) and e.id=a.object_id where database_id=DB_ID() --and d.name in ('WFPUSER_A0120_READY','','') order by total_user_cost desc ,c.avg_total_user_cost desc,c.user_seeks desc,c.user_scans desc --order by c.avg_total_user_cost desc --order by d.name,c.avg_user_impact desc --order by c.avg_user_impact desc
Sqlserver 2005+:数据库【推荐】的【丢失索引】信息
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
java 监听 sqlserver 数据库的变化
java 监听 sqlserver 数据库的变化
Server SQL Java -
mysql 数据库丢失 mysql表丢失
(给数据分析与开发加星标,提升数据技能)日常工作中,总会有因手抖、写错条件、写错表名、错连生产库造成的误删库表和数据的事情发生。那么,如果连数据都恢复不了,还要什么 DBA。1 前言数据恢复的前提的做好备份,且开启 binlog,格式为 row。如果没有备份文件,那么删掉库表后就真的删掉了,lsof 中还有记录的话,有可能恢复一部分文件。但若刚好数据库没有打开这个表文件,那就只能跑路了。如果没有开
mysql 数据库丢失 mysql 备份表 mysql备份表 mysql没有my.ini文件 mysql表一定要主键吗