Problem solve Get help with specific problems with your technologies, process and projects.

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:

({ 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.

Dig Deeper on Enterprise infrastructure management

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.