主键和索引 [英] Primary Key and Indexing
问题描述
大家好,
请考虑这种情况....
我有一个叫发票的表
以下各列
1. InvoiceID(int主键)
2. InvoiceNo(nvarchar(20),唯一)
3. InvoiceDate
4. CustomerID
默认情况下,"PK_Invoice"索引创建为聚簇索引.
但是我想使用InvoiceDate进行集群,因此我添加了一个名为"IX_Invoice_Date"的索引.
并将创建为群集"属性更改为true.我的问题是,索引"PK_Invoice"是否仍将继续运行,或者我是否需要另一个索引用于"InvoiceID"字段?
谢谢
Hello everyone,
Please consider the scenario....
I have a table called Invoice
with following columns
1. InvoiceID (int Primary Key)
2. InvoiceNo (nvarchar(20), unique)
3. InvoiceDate
4. CustomerID
By default "PK_Invoice" index is created as clustered index.
but i want to cluster using InvoiceDate, so i add an index called "IX_Invoice_Date"
and change the "Create as clustered" property to true. My Question is, will the index "PK_Invoice" still continue to be operational or will i need another index for "InvoiceID" feild?
Thank you
推荐答案
主键可以基于非聚集索引,因此,如果您构建表以便为InvoiceDate创建聚集索引,则主键将仍然可以使用.主键的聚集索引只是默认的设置".
Primary key can be based on a non-clustered index so if you build the table so that the clustered index is created for InvoiceDate, your primary key will still be operational. Clustered index for primary key is just the default ''setting''.
这篇关于主键和索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!