Is it bad to have a non-clustered index that contains the primary key from the clustered index?

后端 未结 4 1536
长情又很酷
长情又很酷 2021-01-05 06:59

If you have a table with a clustered index on the Primary Key (int), is it redundant and bad to have one (ore more) non-clustered indexes that include that primary key colum

4条回答
  •  借酒劲吻你
    2021-01-05 07:40

    Yes, it is typically not necessary, because the columns of the clustered index are already added to each index entry in the non-clustered index.

    Why? The value of the clustered key is what really allow SQL Server to "find" a row of data - it's the "pointer" to the actual data - so obviuosly, it has to be stored in the non-clustered index. If you have looked up "Smith, John" and you need to know more about this person, you need to go to the actual data --> and that is done by including the value of the clustering key in the index node of the non-clustered index.

    That clustered key value is already there, and thus typically it's redundant and unnecessary to add that value again, explicitly, to your non-clustered index. It's bad in that it just simply wastes space without giving you any benefit.

提交回复
热议问题