当前位置: 移动技术网 > IT编程>数据库>MSSQL > 查询SQL Server Index上次Rebuild时间的方法

查询SQL Server Index上次Rebuild时间的方法

2017年12月12日  | 移动技术网IT编程  | 我要评论

秋水翻译,呀呀学习网,免费图书网

朋友有一个rebuild index的job执行一般停掉了,问我是否可以查看哪些index已经被rebuild过了。本来以为sys.index或者sys.objects会存储类似的信息,结果没有找到。
 
从网上查了一下,sql server没有存储类似的信息。但是因为rebuild index会自动更新统计信息,而统计信息的更新时间是可以获得的。所以我们可以大致根据统计信息的时间来估计。
因为统计信息的更新也有可能是达到更新的阀值所做的更新,所以不是非常的准确。
 
具体的脚本如下:

select object_name(object_id) [tablename],
    name [indexname],
    stats_date(object_id, stats_id)[laststatsupdate]
from sys.stats
where name not like '_wa%'--
and stats_date(object_id, stats_id)is not null
and objectproperty(object_id,'ismsshipped') = 0 --查询用户自定义的
order by tablename, indexname
 
-----代码来自于:http://stackoverflow.com/questions/2831293/tsql-know-when-index-rebuild-reorg-or-updatestatistics-was-last-run-on-sql-ser

 可以根据自己的增加条件筛选。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网