是否有可能一个聚集索引转换为非聚集索引或 非聚集索引聚集索引在SQL Server 2005将聚集索引转换为非聚集索引?
请转换此查询到聚集索引:
create index index1 on mytable(firstcolumn)
请转换此查询转化为非聚集索引:
create clustered index clusindex1 on mytable(cluscolumn)
是否有可能一个聚集索引转换为非聚集索引或 非聚集索引聚集索引在SQL Server 2005将聚集索引转换为非聚集索引?
请转换此查询到聚集索引:
create index index1 on mytable(firstcolumn)
请转换此查询转化为非聚集索引:
create clustered index clusindex1 on mytable(cluscolumn)
那些不是查询;他们是DDL命令。 掉落并根据需要,像这样重新创建索引:
drop index mytable.index1
go
create nonclustered index index1 on mytable (firstcolumn asc)
go
还有更多的它比满足眼睛
创建聚簇索引
drop index mytable.clusindex1
go
create clustered index clusindex1 on mytable(cluscolumn)
创建非聚集索引
drop index mytable.clusindex1
go
create index clusindex1 on mytable(cluscolumn) --non clustered is default
说了这么多,你每个表只能有一个聚簇索引,所以如果您尝试删除索引并将其重新创建为聚簇索引,则如果您已有聚簇索引,则该索引将失败。每当您删除聚簇索引时,所有非聚簇索引也将被删除并重新创建指向堆,然后在创建聚簇索引时再次删除并重新创建,现在指向聚簇索引(查找WITH DROP_EXISTING子句)
我会说,查找如何索引在Books On Line中工作,然后再开始删除和重新创建索引
我还想知道聚集索引是否可以转换(更改)为非聚集索引。我不相信这是可以做到的。必须首先删除现有的聚簇索引,然后才能创建新的非聚簇索引(可能与聚簇索引具有相同的名称)。将非聚集索引转换为聚集索引也是如此。
我不知道你为什么要求'查询'被转换,但@Tahbaza是正确的,因为你包含在你的问题中的代码不是真正的查询。它们是用于更改“数据定义”(即数据库的架构[结构])的T-SQL语句。
如果您添加一个包含所有列的索引(无论是在索引中还是作为包含列),这与第二个聚簇索引基本相同 – Andomar 2010-08-29 18:03:50
如果表的宽度超过900个字节或者如果您有您的表格中有16列以上 – SQLMenace 2010-08-29 18:20:00
您可以有多达1023个包含任意宽度AFAIK的列。 – 2010-08-29 18:33:02