要查找上次更新日期的状态,只需使用此查询即可完成:
SELECT
OBJECT_NAME(object_id) AS [ObjectName],
[name] AS [StatisticName],
STATS_DATE([object_id],
[stats_id]) AS [StatisticUpdateDate]
FROM
sys.stats;
除了知道何时(日期和时间),我还可以查询哪个表来查找统计数据上次更新的采样百分比?知道执行的统计数据是否有价值,但知道何时执行哪些统计数据更有价值。
答案 0 :(得分:1)
以下是我的最终SQL,它可以在进行快速验证时为您提供有关统计数据的非常有价值的信息:
[select stats.object_id,
stats.name stat_name,
stats.stats_id,
objects.name table_name,
stats_date(stats.object_id, stats.stats_id) last_stat_update,
sp.rows_sampled rows_sampled_when_last_stat_update,
sp.rows total_rows_when_last_stat_update,
(to_number(sp.rows_sampled) / to_number(sp.rows)) * 100 percent_rows_sampled,
sp.modification_counter changes_since_last_stat_update
from sys.objects
join sys.stats
on stats.object_id = objects.object_id
cross apply sys.dm_db_stats_properties(stats.object_id, stats.stats_id) sp
where objects.type_desc = 'USER_TABLE']
答案 1 :(得分:0)
看看这是否是你要找的。 p>
SELECT
OBJECT_NAME([sp].[object_id]) AS "Table",
[sp].[stats_id] AS "Statistic ID",
[s].[name] AS "Statistic",
[sp].[last_updated] AS "Last Updated",
[sp].[rows],
[sp].[rows_sampled],
[sp].[unfiltered_rows],
[sp].[modification_counter] AS "Modifications"
FROM [sys].[stats] AS [s]
OUTER APPLY sys.dm_db_stats_properties ([s].[object_id],[s].[stats_id]) AS [sp]