主键和聚集索引的关系

编程入门 行业动态 更新时间:2024-10-28 00:13:55
本文介绍了主键和聚集索引的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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.

更多推荐

主键和聚集索引的关系

本文发布于:2023-10-15 02:21:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492968.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主键   索引   关系

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!