Perform online index defrag

New command that allows this.

SQL Server 2000 added a new method for defragmenting your indexes, the DBCC INDEXDEFRAG command. There are some limitations associated with this command versus its alternative, the DBCC DBREINDEX command, namely that it doesn't completely defragment the index. However, the DBCC INDEXDEFRAG command provides a powerful alternative because it allows you to do background defragmentation while keeping your index and the table that depends...

on it online and in use, something referred to as online reorg.

The DBCC INDEXDEFRAG command has the following syntax:

    DBCC INDEXDEFRAG
({ database_name | database_id | 0}
         , {table_name | table_id | 'view_name' | view_id}
         , {index_name | index_id}
         ) [WITH NO_INFOMSGS]

These options are similar to the CREATE INDEX statement, and contain the means for sorting and fill factors. For a fill factor set to 0 (as above) the original fill factor for the index is used. When you use this command with a table every index of that table is defragged; or you can specify individual indexes by name or ID. To use this command you have to have to be the owner of the table or have membership in the sysadmin server role, db_owner or db_ddladmin database roles.

DBCC INDEXDEFRAG works by defragmenting the leaf levels of the indexes specified. This won't create a completely sorted index, but will provide you with the most of the performance benefits associated with defragmentation.


Barrie Sosinsky is president of consulting company Sosinsky and Associates (Medfield MA). He has written extensively on a variety of computer topics. His company specializes in custom software (database and Web related), training and technical documentation.


This was first published in April 2003

Dig deeper on Enterprise Infrastructure Management

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchServerVirtualization

SearchCloudComputing

SearchExchange

SearchSQLServer

SearchWinIT

SearchEnterpriseDesktop

SearchVirtualDesktop

Close