Rebuilds one or more indexes for a table in the specified database.
DBCC DBREINDEX
( [ 'database.owner.table_name' [, index_name [, fillfactor ] ] ]
) [WITH NO_INFOMSGS]
DBCC DBREINDEX rebuilds an index for a table or all indexes defined for a table. By allowing an index to be rebuilt dynamically, indexes enforcing either PRIMARY KEY or UNIQUE constraints can be rebuilt without having to drop and re-create those constraints. This means an index can be rebuilt without knowing the table’s structure or constraints, which could occur after a bulk copy of data into the table.
If either index_name or fillfactor is specified, all preceding parameters must also be specified.
DBCC DBREINDEX can rebuild all of the indexes for a table in one statement, which is easier than coding multiple DROP INDEX and CREATE INDEX statements. Because the work is done by one statement, DBCC DBREINDEX is automatically atomic, while individual DROP INDEX and CREATE INDEX statements would have to be put in a transaction to be atomic. Also, DBCC DBREINDEX can take advantage of more optimizations with DBCC DBREINDEX than it can with individual DROP INDEX and CREATE INDEX statements.
DBCC DBREINDEX is not supported for use on system tables.
Whether or not any of the options (except NO_INFOMSGS) are specified (the table name must be specified), DBCC DBREINDEX returns this result set; this example uses the authors table of the pubs database (values will vary):
Index (ID = 1) is being rebuilt.
Index (ID = 2) is being rebuilt.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC DBREINDEX returns this result set (message) if the NO_INFOMSGS option is specified:
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC DBREINDEX permissions default to members of the sysadmin fixed server role or the db_owner fixed database role, or the table owner, and are not transferable.
This example rebuilds the au_nmind clustered index with a fillfactor of 80 on the authors table in the pubs database.
DBCC DBREINDEX ('pubs.dbo.authors', UPKCL_auidind, 80)
This example rebuilds all indexes on the authors table using a fillfactor value of 70.
DBCC DBREINDEX (authors, '', 70)
ALTER TABLE | Table and Index Architecture |
CREATE TABLE | DBCC |