我想修改 SQL Azure 表上的现有主键。
它目前只有一列,我想添加另一列。
现在,在 SQL Server 2008 上这是小菜一碟,只是在 SSMS 中做到了,噗。完毕。如果我从 SQL Server 编写 PK,这就是 PK 的样子:
ALTER TABLE [dbo].[Friend] ADD CONSTRAINT [PK_Friend] PRIMARY KEY CLUSTERED
(
[UserId] ASC,
[Id] ASC
)
Run Code Online (Sandbox Code Playgroud)
但是,在 SQL Azure 上,当我尝试执行上述操作时,它当然会失败:
Table 'Friend' already has a primary key defined on it.
很好,所以我试着放下钥匙:
Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.
好的,所以我尝试创建一个临时聚集索引以删除 PK:
CREATE CLUSTERED INDEX IX_Test ON [Friend] ([UserId],[Id])
Run Code Online (Sandbox Code Playgroud)
结果是: …