我在网上发现的关于数据库索引的一些笔记中读到了这个声明。 "一个文件最多只能有一个主索引或一个聚簇索引,但不能同时包含两个。" 为什么文件不能同时具有主索引和聚簇索引?是因为一个文件最多只能有一个物理排序字段吗?
谢谢!
答案 0 :(得分:1)
A generated (primary) clustered index is the primary index, that is why you cannot have both.
If you declare one column as the primary index and is valid the database will use that.
If you don't declare one column as the primary index but have one column that is unique, not null, and has a value that can be indexed, for example int
or a fixed lenght char
, but not a text
or blob
column, the system will use that as the primary index.
If you don't have one column that fits the criteria, then the system will try to find a group of columns that fit the criteria and use that as the primary (clustered) index.
If that is still not possible then it will create a hidden column and index the table using that column internally.
But the statement itself is not really correct, you could have a primary key, clustered or not and still have some clustered secondary indexes.
What the statement is saying is that you cannot have two primary indexes in one table.