如何在 SQL Server 2005 中将聚集主键转换为非聚集主键而不删除引用外键

发布于 2024-08-21 17:42:05 字数 183 浏览 1 评论 0原文

我在 GUID 列上创建聚集主键时犯了错误。 有许多表引用具有定义的外键的表。 表的大小并不重要。

我想将其从集群转换为非集群,而无需手动删除和重新创建任何外键甚至主键约束。

是否有可能在 MS SQL2005 中实现这一点,如果可以的话如何实现?

如果可以的话,是否可以在线实现(没有数据库停机时间)?

I've made mistake creating clustered primary key on GUID column.
There are many tables that reference that table with defined foreign keys.
Table size is not significant.

I would like to convert it from clustered to non-clustered without manually dropping and recreating any foreign keys or even primary key constraint.

Is it possible to achieve that in MS SQL2005 and how if yes ?

Is it possible to achieve that ONLINE (without db down time) if yes ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傻比既视感 2024-08-28 17:42:05

您可以尝试先创建唯一的非聚集NC索引,然后删除聚集PK。 FK 应该识别这个其他索引(但可能不会:从未尝试过)。

当您运行 ALTER TABLE 删除群集 PK 时,请使用 ONLINE 选项。但是,它仅在企业版中可用。

ALTER TABLE Mytable DROP CONSTRAINT PK_Mytable WITH (ONLINE = ON)

您不能将 ONLINE 用于 ADD CONSTRAINT 位。

基本上,您的选择是有限的,不会阻塞,或者先创建另一个表并将数据移动到...

You could try creating the unique nonclustered NC index first, then drop the clustered PK. The FK should recognise this other index (but might not: never tried it).

When you run ALTER TABLE to drop the clustered PK use the ONLINE option. However, it's only available in Enterprise edition.

ALTER TABLE Mytable DROP CONSTRAINT PK_Mytable WITH (ONLINE = ON)

You can't use ONLINE for the ADD CONSTRAINT bit.

Basically, your options are limited without blocking, or creating another table first and moving data over...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文