SQL Server misunderstanding 30th on the 29th day on the wrong heap debris _mssql

Source: Internet
Author: User
Myth #29: You can defragment the heap after you drop the heap by a clustered index
nooooooooooooo!!!

To heap a clustered index and drop it seems to me to be the top 2 in addition to shrinking the database.
If you see fragments on the heap through sys.dm_db_index_physical_stats (or an older version of DBCC SHOWCONTIG), do not defragment the heap by creating a clustered index and then deleting the clustered index. A good practice should be to set up a clustered index and not delete it, and there is already a lot of information on how to choose an ideal clustered index key--narrow, rarely changed, unique, self increasing. Kimberly has an article summarizing this: ever-increasing Clustering key-the Clustered Index debate..........again!(Note that this is based on the SQL Server 2005 version) and I have an example of this: An example of a nasty cluster key。
You can also pass alter TABLE in SQL Server 2008 ... Rebuild to clear heap fragments, but this practice and the establishment of a clustered index after the deletion of the same evil.
If you want to ask, why do I have an obsession with this? Well, let me explain: each row in the nonclustered index points to a link to a RID or a clustered index key (see for more information: What happens if I Drop a Clustered Index?, this link will appear in one of the following two ways:
    • If the table in which the nonclustered index is located is a heap, then the link is a RID.
    • If the table in which the nonclustered index is located is a clustered index, then the link is the clustered index key.
      If you want to know more about this, see the link at the bottom of the article.
      So it's not hard to see that if you want to turn the heap into a clustered index, then all the rids of the nonclustered index are invalidated, so all nonclustered indexes need to be rebuilt. Similarly, if you delete a clustered index key, all clustered index keys stored on all nonclustered indexes will fail, and therefore all nonclustered indexes need to be rebuilt.
      Simply put, if you create and then delete the clustered index, all nonclustered indexes will be rebuilt two times.
      If you are using ALTER TABLE of SQL Server 2008 ... Rebuild to defragment the heap, you also need to rebuild all nonclustered indexes because all the rids will change.
      So what about "rebuilding" a clustered index? This depends on the version of SQL Server and whether you are indexing the rebuild or changing the index. A common misconception is that partitioning a table will change the clustered index key, but not in fact. For those operations that cause nonclustered index rebuilds, see the following list: Indexes fromEvery angle:what happens to non-clustered Indexes when the table structure be c Hanged?
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.