good/doesn't matter/bad to include Primary Key in covering index?

前端 未结 2 1605
孤街浪徒
孤街浪徒 2020-12-24 05:05

is is good or doesn\'t matter or bad to INCLUDE the primary key in a covering index??

CREATE NONCLUSTERED INDEX index_         


        
2条回答
  •  我在风中等你
    2020-12-24 05:19

    If you are clustering on your PK, then it doesn't matter. SQL Server will disregard it since all non-clustered indexes contain the clustered index key for that row as part of their definition.

    It won't use any extra space in the index, but it's redundant to include it in the definition.

    If your PK isn't included in your clustered index, then only include it if you will need to retrieve that field as a part of the same query that uses the index.

    Also bear in mind when you INCLUDE a field in an index, it's NOT in the non-leaf nodes, i.e. the index is not sorted on that value.

提交回复
热议问题