我可以拥有没有聚簇索引的主键吗?还可以有多值聚集索引吗? [英] Can I have a primary key without clustered index ? Also can I have multivalued clustered index?

查看:173
本文介绍了我可以拥有没有聚簇索引的主键吗?还可以有多值聚集索引吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我想了解以下问题的答案:

Folks, I would like to understand the answer for the following questions:

  1. 我可以拥有没有聚簇索引的主键吗? (我知道我们在列上创建主键约束时,默认情况下会创建聚簇索引.因此,在这种情况下,应如何停用聚簇索引?)

  1. Can I have a primary key without clustered index ? ( I am aware that when we create primary key constraint on a column, it by default creates a clustered index. So in that case, how should I deactivate clustered index ?)

我可以有一个包含多个列的聚集索引吗? (就像非集群一样,我可以为一个非集群索引连接不同的列).

Can I have a clustered index with multiple columns together ? (Like in non-clustered where I can join different columns for a single non-clustered index).

推荐答案

(此答案仅适用于SQL Server 2005+.我对MySQL一无所知.)

(This answer is for SQL Server 2005+ only. I know nothing about MySQL.)

我可以拥有没有聚簇索引的主键吗?

Can I have a primary key without clustered index?

是的.如前所述,默认情况下,主键约束由聚簇索引支持.您可以通过如下声明约束来告诉SQL Server使用非聚集索引来支持约束:

Yes. As you mentioned, a primary key constraint is backed by a clustered index by default. You can tell SQL Server to back the constraint with a nonclustered index by declaring the constraint as follows:

ALTER TABLE MyTable
    ADD CONSTRAINT PK_MyTable
        PRIMARY KEY NONCLUSTERED(Col1);


我可以有一个包含多个列的聚集索引吗? (就像非集群一样,我可以为一个非集群索引连接不同的列).

Can I have a clustered index with multiple columns together ? (Like in non-clustered where I can join different columns for a single non-clustered index).

是的,您可以在索引键中定义一个具有多列的索引.实际上,它与非聚集索引没有什么不同.

Yes, you can define an index with more than one column in the index key. It's really no different than a nonclustered index.

CREATE UNIQUE CLUSTERED INDEX IX_MyTable_Clus
    ON MyTable(Col1, Col2, Col3);


参考文献: ALTER TABLE


References: ALTER TABLE, CREATE INDEX

这篇关于我可以拥有没有聚簇索引的主键吗?还可以有多值聚集索引吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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