What exactly does the following statement do? Does it reindex all tables named '?' with a fill factor of 80% ?
EXEC sp_MSforeachtable @command1="print '?' DBCC DBREINDEX ('?', ' ', 80)"
It did improve query time from 23 seconds to almost instantly but I'd like to understand why.
The statement Updates user-defined, auto-created statistics and it also updates the statistics associated with the index.
REINDEX rebuilds an index using the data stored in the index's table, replacing the old copy of the index. There are several scenarios in which to use REINDEX: An index has become corrupted, and no longer contains valid data.
Microsoft SQL Server Database Console Commands (DBCC) are used for checking database integrity; performing maintenance operations on databases, tables, indexes, and filegroups; and collecting and displaying information during troubleshooting issues.
Not quite - when you use sp_MSforeachtable
, the question mark is a placeholder for the the table name (as it loops through each table in turn).
In reply to your second question from the comments, yes - according to the documentation on DBCC DBREINDEX about the second argument:
If index_name is specified, table_name must be specified. If index_name is not specified or is " ", all indexes for the table are rebuilt.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With