The method of querying the last rebuild time of SQL Server index

Time:2021-4-8

A friend has a job whose execution of rebuild index has stopped. He asked me if I could check which indexes have been rebuilt. I thought Sys.index perhaps Sys.objects Similar information will be stored and not found.
 
Check from the Internet, SQL server does not store similar information. But because rebuild index will update statistics automatically, the update time of statistics can be obtained. So we can estimate it roughly according to the time of statistical information.
Because the update of statistical information may also be done when the update threshold is reached, it is not very accurate.
 
The specific script is as follows:

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, 'ismshipped') = 0 -- Query user-defined
ORDER BY TableName, IndexName
 
-----Code from: http://stackoverflow.com/questions/2831293/tsql-know-when-index-rebuild-reorg-or-updatestatistics-was-last-run-on-sql-ser

You can select according to your own conditions.