我的表中有一个Bit列,由0和1组成。我需要在该列上创建分区索引。我试过以下查询,但我无法做到。你能帮我吗?
CREATE PARTITION FUNCTION IsLockedPF (bit)
AS RANGE RIGHT FOR VALUES (0,1)
GO
CREATE PARTITION SCHEME myPartitionScheme
AS PARTITION IsLockedPF ALL TO ([PRIMARY])
GO
SELECT ps.name,pf.name,boundary_id,value
FROM sys.partition_schemes ps
INNER JOIN sys.partition_functions pf ON pf.function_id=ps.function_id
INNER JOIN sys.partition_range_values prf ON pf.function_id=prf.function_id
ALTER TABLE COE.OrdersTBU DROP CONSTRAINT PK_OrdersTBU
GO
ALTER TABLE COE.OrdersTBU ADD CONSTRAINT PK_OrdersTBU PRIMARY KEY NONCLUSTERED (IsLocked)
WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE CLUSTERED INDEX IX_TABLE1_partitioncol ON COE.OrdersTBU (IsLocked)
WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
ON myPartitionScheme(IsLocked)
GO
我的错误如下:
Msg 3728,Level 16,State 1,Line 1
'PK_OrdersTBU'不是约束 消息3727,级别16,状态0,行1 无法删除约束。请参阅先前的错误 消息1505,级别16,状态1,行1 CREATE UNIQUE INDEX语句终止,因为找到了对象名称'coe.OrdersTBU'和索引名称'PK_OrdersTBU'的重复键。重复键值为(0) Msg 1750,Level 16,State 0,Line 1
无法创建约束。请参阅先前的错误 声明已经终止。
答案 0 :(得分:1)
我猜测PK_OrdersTBU不是主键的名称,但可能是索引。试试这些:
如果它是PK,这应该告诉你它是:
select xtype from sysobjects where name = 'PK_OrdersTBU'
如果没有返回任何记录,请执行以下操作:
select * from sysindexes where name = 'PK_OrdersTBU'
如果是这样,你有一个索引,它们会被不同地删除。
答案 1 :(得分:0)
看起来你有一个重复的PK_OrdersTBU。