Uncategorized

Statistics overview with modifications, rows and age

SELECT              
	[sc].[name] [SchemaName],
	[t].[name] [TableName],
	[s].[name] [StatisticsName],
	[ddsp].[modification_counter] [Modifications],
	[ddsp].[rows] [Rows],
	[ddsp].[rows_sampled] [RowsSampled],
	DATEDIFF(DAY, STATS_DATE([ddsp].[object_id], [ddsp].[stats_id]), GETDATE()) [AgeDays]
FROM [sys].[stats] [s]
	CROSS APPLY [sys].[dm_db_stats_properties]([s].[object_id], [s].[stats_id]) [ddsp]
	INNER JOIN [sys].[tables] [t] ON [t].[object_id] = [s].[object_id]
	INNER JOIN [sys].[schemas] [sc] ON [sc].[schema_id] = [t].[schema_id]
WHERE [sc].[name] <> 'sys' 
ORDER BY [SchemaName], [TableName], [StatisticsName]