Should primary key clustered index columns added to the non clustered indexes?

让人想犯罪 __ 提交于 2020-01-05 07:44:07

问题


Ok here is a non clustered index features

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


回答1:


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.



来源:https://stackoverflow.com/questions/14349260/should-primary-key-clustered-index-columns-added-to-the-non-clustered-indexes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!