SQL 如何将主键更改为非集群?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2604452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 05:57:16  来源:igfitidea点击:

How to change the primary key to be non-clustered?

sqlsql-server-2005clustered-indexalter

提问by AngryHacker

Part-time reluctant DBA here. I want to change an existing primary key index from clustered to non-clustered. And the syntax is escaping me.

在这里兼职不情愿的 DBA。我想将现有的主键索引从聚集更改为非聚集。语法正在逃避我。

This is how it's scripted out right now.

这就是它现在的脚本编写方式。

ALTER TABLE [dbo].[Config] WITH NOCHECK ADD 
    CONSTRAINT [PK_Config] PRIMARY KEY  CLUSTERED 
    (
        [ConfigID]
    )  ON [PRIMARY] 

I am not seeing an ALTER CONSTRAINT statement in the online docs.

我在在线文档中没有看到 ALTER CONSTRAINT 语句。

回答by Andomar

Drop the clustered index, then recreate the primary key as non-clustered:

删除聚集索引,然后将主键重新创建为非聚集索引:

ALTER TABLE dbo.Config DROP CONSTRAINT PK_Config
go
ALTER TABLE dbo.Config ADD CONSTRAINT PK_Config 
    PRIMARY KEY NONCLUSTERED (ConfigID)