SQl Azure切换群集和非群集索引

时间:2016-07-22 08:30:06

标签: sql azure azure-sql-database database-indexes

我的桌子上有两个索引:

CREATE CLUSTERED INDEX [IXAddrbookCrtDtm] ON [dbo].[Addrbook]
(
     [AbkOrgGrpID] ASC,
     [AddrbookID] ASC
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
      SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF,
      ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
GO

ALTER TABLE [dbo].[Addrbook]
    ADD CONSTRAINT [PKAddrbook_New]
      PRIMARY KEY NONCLUSTERED 
      (
       [AbkOrgGrpID] ASC,
       [AddrbookID] ASC
      )
      WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
            SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, 
            ONLINE = OFF, ALLOW_ROW_LOCKS = ON,
           ALLOW_PAGE_LOCKS = ON)
GO

我需要只有一个Clustered Primary Key Index而不是两个以上。删除和重新创建表不是一种选择。

是否有像

这样的东西
CREATE CLUSTERED INDEX IXAddrbookCrtDtm ON
    Addrbook(AbkOrgGrpID,AddrbookID)
    PRIMARY KEY  WITH (DROP_EXISTING = ON);

这样我就可以删除非聚集索引了吗?

1 个答案:

答案 0 :(得分:0)

删除索引并创建新索引,而不是删除表格。

涉及的步骤..

删除索引

  

在[dbo]上删除索引IXAddrbookCrtDtm。[Addrbook]

删除约束

  

alter table [dbo]。[Addrbook]   删除约束PKAddrbook_New

创建新的主键

  

alter table [dbo]。[Addrbook]添加主键(AbkOrgGrpID,AddrbookID)