“主键"关键字与 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.