What's the difference between INDEXDEFRAG and DBREINDEX with MSSQL
DBCC INDEXDEFRAG
- DBCC INDEXDEFRAG is an online operation. It can be used without locking out users.
- DBCC INDEXDEFRAG has no long-term locks that block running queries or updates. Only the local pages are locked.
- DBCC INDEXDEFRAG can be used at any time, there are no restrictions.
- If low amount of fragmentation, then it's lot faster than DBCC DBREINDEX.
- If high amount of fragmentation, then it's lot slower than DBCC DBREINDEX.
- DBCC INDEXDEFRAG compacts the pages of an index and empty pages are removed.
- DBCC INDEXDEFRAG can be interrupted. When DBCC INDEXDEFRAG is interrupted, it keeps the optimization already done.
- DBCC INDEXDEFRAG operations are logged. You cannot disable the logging.
- DBCC INDEXDEFRAG cannot defragment a disabled index.
- DBCC INDEXDEFRAG cannot defragment an index with page locking set to OFF.
- DBCC INDEXDEFRAG cannot defragment system tables.
- DBCC INDEXDEFRAG does not work if indexes are interleaved on disk.
- DBCC INDEXDEFRAG will be deprecated in future versions. When? Microsoft has not announced which version of SQL Server will deprecate it.
- You should use ALTER INDEX INSTEAD.
DBCC DBREINDEX
- DBCC DBREINDEX rebuilds one index or all indexes for a table.
- DBCC DBREINDEX is an offline operation.
- If low amount of fragmentation, then it's lot slower than DBCC DBREINDEX.
- If high amount of fragmentation, then it's lot faster than DBCC DBREINDEX.
- DBCC DBREINDEX supports rebuilding clustered indexes.
- If DBCC DBREINDEX rebuilds a nonclustered index then it will hold a shared lock on the table.
- If DBCC DBREINDEX rebuilds a clustered index then it will hold an exclusive lock on the table.
- DBCC REINDEX will be deprecated in future versions. When? Microsoft has not announced which version of SQL Server will deprecate it.
- You should use ALTER INDEX INSTEAD.

