非聚集索引中的唯一键约束 [英] Unique key constraint in Non-clustered index

查看:116
本文介绍了非聚集索引中的唯一键约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



是否必须在列中使用唯一值来创建表中列的非聚集索引?

要创建非聚集索引的列不是表的主键。



请提供一些示例或链接可能会有很大帮助。



谢谢

Hi All,

Is it mandatory to have unique values in column to create non clustered index with the column in the table?
The column over which the non clustered index is to be created is not the primary key of the table.

Please provide some examples or links that may help a lot.

Thanks

推荐答案

黑人大师



不,它不需要对非聚集索引具有唯一约束。如果您是一家汽车公司,您可能会有一个简单的汇总表,其中包含您所制造的所有汽车。



Car_History
VIN编号

颜色

型号

生成日期

发售日期



Car_History表可能在VIN编号上有一个主键/索引。这将是一个独特的约束。但他们可能还会在制造/销售汽车的两个日期列中有一个索引。这些列将具有重复的条目,因为它易于生产并且每天销售多辆汽车。在这种情况下,将这些列编入索引是有意义的。然后可以在不同的时间段运行摘要报告,以帮助理解产品的销售周期。



在这种情况下,索引中不可能有唯一值因为日期可能会重复!



我希望这会有所帮助!



Hogan
Master Black

No, its not required to have a unique constraint on a non-clustered index. If you were an automotive company, you might have a simple summary table with all of the cars you ever made.

Car_History
VIN Number
Color
Model
Date Produced
Date Sold

The Car_History table would likely have a primary key/index on VIN Number. That would be a unique constraint. But they would probably also have an index on the two date columns for when cars were made/sold. Those columns would have duplicate entries as its easy to produce and sell more than one car each day. In this instance, it would make sense to index these columns. Then summary reports could be run on different time periods to help understand the sales cycle of products.

In this instance, it would be impossible to have unique values in the index as the dates would surly be duplicated!

I hope this helps!

Hogan


这篇关于非聚集索引中的唯一键约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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