主键聚簇索引列是否应添加到非聚簇索引? [英] Should primary key clustered index columns added to the non clustered indexes?

查看:173
本文介绍了主键聚簇索引列是否应添加到非聚簇索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是一个非聚集索引功能

Ok here is a non clustered index features

现在您可以看到Id是Identity列,它是主键和群集。我可以将它包含在索引列中,并将索引标记为唯一,或者不将其包含在索引本身中,并将其添加为包含的列。

Now as you can see Id is the Identity column which is primary key and clustered. I can either include it into the index columns and mark index as unique or not include it to the index itself and add it as included columns.

应该选择哪一个?为什么?谢谢

Which one should be selected and why ? thank you

推荐答案

无论是否明确包含,集群密钥都会自动包含在非聚集索引中。换句话说 - 不包括它,除非你需要使用一个谓词来过滤集群密钥然后再使用其他几列(按照这个顺序) - 在这种情况下强制它作为第一列是有意义的,因为它将以物理方式存储为最后一列。

The clustered key is automatically included in the nonclustered index, whether you include it explicitly or not. In other words - don't include it, unless you need to use a predicate that filters on the clustered key and then a couple of other columns (in that order) - in that case it may make sense to force it as the first column, as it'll otherwise be stored physically as the last column.

这篇关于主键聚簇索引列是否应添加到非聚簇索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆