How to rebuild an index in a SQL Server 2000 database

Source: Internet
Author: User
Tags create index key sql

When you create an index in a database, the index information used by the query is stored in the index page. A continuous index page is linked by a pointer from one page to the next. When changes to the data affect the index, the information in the index may be dispersed in the database. Rebuilding an index can rearrange the storage of index data (also including table data for clustered indexes) to remove fragmentation. This can improve disk performance by reducing the number of page reads required to obtain the requested data.

In Microsoft®sql server™2000, if you want to re-create the index with one step, and you do not want to delete the old index and re-create the same index, using the DROP_EXISTING clause of the CREATE index statement can improve efficiency. This benefit applies both to clustered indexes and to nonclustered indexes.

Rebuilding a clustered index by deleting the old index and recreating the same index is an expensive method because all level two indexes use a clustered key to point to the data row. If you simply delete the clustered index and re-create it, all nonclustered indexes are deleted and recreated two times. This situation can occur once the clustered index is deleted and the index is rebuilt again. This expensive approach can be avoided by recreating the index in one step. When you re-create the index in one step, you tell SQL Server to rearrange the existing indexes, avoiding the unnecessary work of deleting and recreating nonclustered indexes. Another important advantage of this approach is that you can use the data sort order in an existing index to avoid reordering the data. This is useful for both clustered and nonclustered indexes, which can significantly reduce the cost of rebuilding the index. Additionally, by using the DBCC dbreindex statement, SQL Server allows one or more indexes to be rebuilt (in one step) on a table without having to rebuild each index separately.

DBCC Dbreindex can also be used to reconstruct indexes that perform PRIMARY key or UNIQUE constraints, without having to delete and create these constraints (because this constraint must be removed before the index can be deleted for an index created to perform a PRIMARY key or a unique constraint). For example, you might need to rebuild an index on the PRIMARY KEY constraint to reconstruct the given fill factor for that index.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.