作为SQL升级的一部分,我目前正在将数据库文件分成多个较小的数据库文件组。
我正在阅读的页面建议您使用此脚本移动聚集索引
CREATE CLUSTERED INDEX <name of the existing clustered index>
ON <Table_name> (<Column1, Column2,…>)
WITH (DROP_EXISTING=ON)
ON [<TargetFileName>]
这不起作用:
The new index definition does not match the constraint being enforced by the existing index.
在SSMS中导航到服务器>数据库>表> TableName>约束显示没有约束。
我通过导航到“服务器”>“数据库”>“表”>“ TableName”>“索引”,找到了聚集索引,然后“脚本作为DROP AND CREATE”来解决了这个问题,
USE [DatabaseName]
GO
/****** Object: Index [TableName$0] Script Date: 04/30/2019 11:01:06 ******/
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TableName]') AND name = N'TableName$0')
ALTER TABLE [dbo].[TableName] DROP CONSTRAINT [TableName$0]
GO
USE [DatabaseName]
GO
/****** Object: Index [TableName$0] Script Date: 04/30/2019 11:01:06 ******/
ALTER TABLE [dbo].[TableName] ADD CONSTRAINT [TableName$0] PRIMARY KEY CLUSTERED
(
[FieldName] 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) ON [Data Filegroup 1]
GO
我将“ ON [Data Filegroup 1]”更改为新的文件组,并且可以正常工作。一切似乎都很好,但是我想检查是否可以这样做。