主键和聚集索引的关系 [英] Relationship of Primary Key and Clustered Index

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

问题描述

TABLE有没有聚集索引的主键?

Can a TABLE have primary key without Clustered Index?

和一个TABLE有没有主键的聚集索引?

and Can a TABLE have Clustered Index without primary key?

任何人都可以简单地告诉我主键和聚集索引的关系?

Can anybody briefly tell me the relationship of primary key and clustered index?

推荐答案

主键是 logical concept - 它是表中行的唯一标识符。因此,它有一堆属性 - 它可能不为null,它必须是唯一的。当然,因为你很可能通过其唯一的标识符搜索记录很多,所以在主键上有一个索引是很好的。

A primary key is a logical concept - it's the unique identifier for a row in a table. As such, it has a bunch of attributes - it may not be null, and it must be unique. Of course, as you're likely to be searching for records by their unique identifier a lot, it would be good to have an index on the primary key.

聚集索引是一个物理概念 - 它是一个影响记录存储在磁盘上的顺序的索引。这使得它在访问数据时速度非常快,但如果主键不是序列号,它可能会减慢写入速度。

A clustered index is a physical concept - it's an index that affects the order in which records are stored on disk. This makes it a very fast index when accessing data, though it may slow down writes if your primary key is not a sequential number.

是的,您可以使用没有聚集索引的主键 - 有时,您可能想要(例如,当您的主键是外键的组合加入表,并且你不想在写时产生磁盘shuffle开销)。

Yes, you can have a primary key without a clustered index - and sometimes, you may want to (for instance when your primary key is a combination of foreign keys on a joining table, and you don't want to incur the disk shuffle overhead when writing).

是的,您可以在不是主键的列上创建聚簇索引。

Yes, you can create a clustered index on columns that aren't a primary key.

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

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