Search This Blog

Sql Server: When was the last time STATISTICs were updated on a table

This is one of the most frequent questions during performance tuning (or during the maintenance plan discussions). There is a quick way to check this for all the STATISTICS on all tables. The function STATS_DATE returns the date when the stats were recomputed.
Example:
1
2
3
4
5
6
SELECT OBJECT_NAME(object_id) AS [Table_Name]
 , STATS_DATE(object_id, stats_id) AS [State_Updated_Date]
 , name AS [Stats_Name]
FROM sys.stats
WHERE OBJECT_NAME(object_id) NOT LIKE 'sys%'
ORDER BY STATS_DATE(object_id, stats_id) DESC
The function STATS_DATE() takes two parameters: object_id of the table and stats_id of the statistic.