我将更改SQL Azure上的主键。但是当使用Microsoft SQL Server Management Studio生成脚本时会引发错误。因为SQL Azure上的每个表都必须包含主键。我无法在创建之前删除它。如果我必须改变它,我该怎么办?如何更改SQL Azure上的主键
脚本生成
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[mytable]') AND name = N'PK_mytable')
ALTER TABLE [dbo].[mytable] DROP CONSTRAINT [PK_mytable]
GO
ALTER TABLE [dbo].[mytable] ADD CONSTRAINT [PK_mytable] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF)
GO
错误消息
Msg 40054, Level 16, State 2, Line 3
Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.
Msg 3727, Level 16, State 0, Line 3
Could not drop constraint. See previous errors.
The statement has been terminated.
Msg 1779, Level 16, State 0, Line 3
Table 't_event_admin' already has a primary key defined on it.
Msg 1750, Level 16, State 0, Line 3
Could not create constraint. See previous errors.
多么奇妙的简单答案。实施出口和娱乐是一个大脑的转折,因为这是我第一次这么做,但最终它非常优雅。 – krillgar 2015-05-18 01:18:37