主键和集群索引之间的关系 [英] Relationship between primary key and cluster index

查看:65
本文介绍了主键和集群索引之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我们可以在不同字段的同一个表上使用主键和集群索引,所以我的问题是在那种情况下,数据是否会根据集群索引或主数据存储在磁盘上如果它是基于簇索引的键(这就是一个表只能有一个簇索引的原因??)那么主键在表中的作用是什么?



我的意思是我们说一个表只能有一个主键,因为数据只能以一个特定的顺序存储在磁盘上,所以这个陈述在上面的场景中是真的吗?



我希望我在这里听起来不会混淆。

Hi,
we can have primary key and cluster index on same table with different field so my question is in that scenario, would data be stored on the disk on the basis of Cluster index or primary key if it is on the basis of Cluster index(and that's the reason a table can have only one cluster index??) then what would be the role of Primary key in the table??

I mean we say that a table can have only one primary key because data can be stored on the disk in only one particular order so is this statement is true on the above scenario??

I hope I am not sounding confuse here.

推荐答案

表上的主键为每一行提供唯一标识符。索引(群集或非群集)用于在读取数据时提高性能。如何设置索引在很大程度上取决于您将如何读取数据...这可能涉及或可能不涉及主键,但通常不涉及。

例如在包含的表中客户数据,您可能会给每个客户一个唯一的号码,但是对于搜索,您可能想要为他们的姓氏编制索引。



这些链接提供更多详细信息

https://www.simple-talk.com / sql / learn-sql-server / sql-server-index-basics / [ ^ ]



http://blog.sqlauthority.com/2013/02/10/sql -server-primary-key-and-nonclustered-index-in-simple-words / [ ^ ]
A primary key on a table provides a unique identifier for each row. An index (clustered or non-clustered) is used to aid performance when reading the data. How you set up an index largely depends on how you are going to read the data ... this may or may not involve the primary key, but frequently doesn't.
For example in a table containing Customer data, you might give each customer a unique number, but for searching you would probably want to index on their surname.

These links give further details
https://www.simple-talk.com/sql/learn-sql-server/sql-server-index-basics/[^]

http://blog.sqlauthority.com/2013/02/10/sql-server-primary-key-and-nonclustered-index-in-simple-words/[^]


这篇关于主键和集群索引之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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