Best way to change clustered index (PK) in SQL 2005

后端 未结 4 817
北海茫月
北海茫月 2021-01-02 23:37

I have a table which has a clustered index on two columns - the primary key for the table. It is defined as follows:

ALTER TABLE Table ADD  CONSTRAINT [PK_T         


        
4条回答
  •  温柔的废话
    2021-01-03 00:39

    If your table is getting up to 1 TB in size and probably has LOTS of rows in it, I would strongly recommend NOT making the clustered index that much fatter!

    First of all, dropping and recreating the clustered index will shuffle around ALL your data at least once - that alone will take ages.

    Secondly, the big compound clustered index you're trying to create will significantly increase the size of all your non-clustered indices (since they contain the whole clustered index value on each leaf node, for the bookmark lookups).

    The question is more: why are you trying to do this?? Couldn't you just add another non-clustered index with those columns, to potentially cover your queries? Why does this have to be the clustered index?? I don't see any advantage in that....

    For more information on indexing and especially the clustered index debate, see Kimberly Tripp's blog on SQL Server indexes - very helpful!

    Marc

提交回复
热议问题