统计日期的SQL查询未返回任何结果

时间:2019-01-29 19:09:01

标签: sql sql-server

我根据在this StackOverflow thread中找到的示例编写了一个查询,以在特定表的列上显示最新统计信息更新的日期。昨天它在我的本地测试系统上运行良好。今天,除非我注释掉where子句,否则它不返回任何行。然后,它返回不到400行,但是这些行都不适合所需的表。

我不知道间隔中可能发生了什么变化,并且我看不出该表上的统计信息怎么可能没有某个日期。

脚本如下所示

任何建议都会有所帮助

SELECT 
       sch.name as [schema],
       o.name as "Table",
       c.name as "Col Name",
       [s].[name] as "Stats",
       [sp].[last_updated] as "Last Updated",
       [sp].[rows],
       [sp].[rows_sampled],
       [sp].[modification_counter] as "Mod Cnt"
FROM
       [sys].[stats] as [s] inner join sys.stats_columns as [sc]
             on (s.stats_id = sc.stats_id) and (s.object_id= sc.object_id)
       inner join sys.columns as [c]
             on c.object_id=sc.object_id and c.column_id=sc.column_id
       inner join sys.objects as o
             on s.object_id=o.object_id
       inner join sys.schemas as sch
             on o.schema_id=sch.schema_id
       OUTER APPLY sys.dm_db_stats_properties ([s].[object_id], [s].[stats_id]) as [sp]
       where [o].[name] = 'ssi_financialdetail'
       ORDER by [sp].[last_updated] ASC

0 个答案:

没有答案