SQL Server – Checking Last Rebuild/Reorganization of Indexes

fragmentationindex-tuningsql serversql-server-2008-r2

I've recently come across a database, which has very high fragmentation on large tables.

Page count > 1'000'000 with fragmentation 99,…

I would like to know how long this table has gone without a reorganize / rebuild.
That way I can review changes made on that date, to try and find a cause. (Also it'd look nice on my report "this database has not been properly maintained since…)

As I'm in the process of setting up a job to quickly reorganize the affected tables (this night probably), any solution that could offer me a history of index operations would be much appreciated. If not, simply knowing that I can check this data in the future would be very helpful.

Best Answer

SQL Server does not maintain when an Index was last rebuild, instead it keeps information when stats were last updated.

That can be found using the STATS_DATE function.

You can use Ola's Index maintenance solution or Michelle Ufford's - Index Defrag Script. These scripts are widely tested in the community and are much flexible so that you can adapt as per your needs in your environment.

SQL Server SP2 for 2008R2 and up has a new DMF sys.dm_db_stats_properties which tells you when your stats were last updated with other info like

modification_counter: number of modifications for the column which leads the statistic, since the last update