Normally I’d leave this sort of thing to a DB to deal with but I stumbled on this a few months back and thought it was rather clever.
USE MyDbName
GO
EXEC sp_MSforeachtable @command1=”print ‘?’”, @command2=”ALTER INDEX ALL ON ? REBUILD WITH (ONLINE=OFF)”
GO
SELECT * FROM sys.Dm_db_index_physical_stats(Db_id(‘MyDbName’),NULL,NULL,NULL,NULL) — This bit just tells you the results
Leave a Reply