将聚集索引转换为非聚集索引?
是否可以将聚集索引转换为非聚集索引或 sql server 2005 中的非聚集索引到聚集索引。
请将此查询转换为聚集索引:
create index index1 on mytable(firstcolumn)
请将此查询转换为非聚集索引:
create clustered index clusindex1 on mytable(cluscolumn)
Is it possible to convert a clustered index to non clustered index or
non clustered index to clustered index in sql server 2005.
Please convert this query into clustered index:
create index index1 on mytable(firstcolumn)
Please convert this query into non clustered index:
create clustered index clusindex1 on mytable(cluscolumn)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
意义远不止于此
创建聚集索引
创建非聚集索引的
,也就是说,每个表只能有一个聚集索引,因此如果您尝试删除索引并将其重新创建为聚集索引,如果您已经有聚集索引,则会失败。每当您删除聚集索引时,所有非聚集索引也将被删除并重新创建指向堆,然后在创建聚集索引时再次删除并重新创建,现在指向聚集索引(查找WITH DROP_EXISTING子句)
我会在开始删除和重新创建索引之前,请先了解一下在线图书中索引的工作原理
There is more to it than meets the eye
to create a clustered index
to create a non clustered index
having said that, you can only have one clustered index per table, so if you try to drop an index and recreate it as a clustered index it will fail if you already have a clustered index. Whenever you drop a clustered index all non clustered indexes will also be dropped and recreated pointing to the heap, and then again dropped and recreated when you create the clustered index, now pointing to the clustered index (look up the WITH DROP_EXISTING clause)
I would say lookup how indexing works in Books On Line before you start dropping and recreating indexes
这些不是查询;而是查询。它们是 DDL 命令。
根据需要删除并重新创建索引,如下所示:
Those aren't queries; they are DDL commands.
Drop and recreate the indexes as desired, like so:
我还想知道聚集索引是否可以转换(更改)为非聚集索引。我不相信这是可以做到的。必须首先删除现有的聚集索引,然后创建新的非聚集索引(可能与聚集索引同名)。将非聚集索引转换为聚集索引也是如此。
我不知道你为什么要求转换“查询”,但@Tahbaza 是正确的,因为你在问题中包含的代码并不是真正的查询。它们是用于更改“数据定义”(即数据库的模式[结构])的 T-SQL 语句。
I also wanted to know whether a clustered index could be converted (altered) to be a non-clustered index. I don't believe this can be done. The existing clustered index has to first be dropped and then the new non-clustered index (possibly with the same name as the clustered index) has to be created. The same is true for converting a non-clustered index to a clustered index.
I have no idea why you're asking for the 'queries' to be converted, but @Tahbaza is correct in that the code you included in your question aren't really queries. They are T-SQL statements for making changes to 'data definitions' (i.e. the schema [structure] of your database).