Tip

Perform online index defrag

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

Requires Free Membership to View

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.