“主键"关键字与 SQL Server 中的聚集索引有何关系?

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

PRIMARY KEY 关键字与 SQL Server 中的聚集索引有何关联?

How does the PRIMARY KEY keyword relate to clustered indexes in SQL Server?

(有些人似乎想回答这个问题而不是 a我问了不同的问题,所以我给了他们一个更好的地方.)

(Some people seem to want to answer this question instead of a different question I asked, so I am giving them a better place to do so.)

推荐答案

表的聚集索引通常定义在主键列上.

The clustered index of a table is normally defined on the primary key columns.

但这并不是一个严格的要求.

This, however is not a strict requirement.

来自 MSDN:

当您创建 PRIMARY KEY 约束时,如果表上的聚集索引尚不存在并且您没有指定唯一的非聚集索引,则会自动创建一个或多个列上的唯一聚集索引.

When you create a PRIMARY KEY constraint, a unique clustered index on the column or columns is automatically created if a clustered index on the table does not already exist and you do not specify a unique nonclustered index.

还有:

如果指定了非聚集主键约束,您可以在主键列以外的列上创建聚集索引.

You can create a clustered index on a column other than primary key column if a nonclustered primary key constraint was specified.

更多推荐

“主键"关键字与 SQL Server 中的聚集索引有何关系?

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

发布评论

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

>www.elefans.com

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