在sql server中的非主键列上对表进行分区

时间:2017-05-04 08:01:26

标签: sql-server partitioning

当我尝试在非主键列上创建表分区时,会出现错误:

CREATE PARTITION FUNCTION PartitionFuncByCntry (int) AS RANGE RIGHT
FOR VALUES  ('10','11','12','15');

CREATE PARTITION SCHEME PartitionSchemeByCntry AS PARTITION
PartitionFuncByCntry TO
([PRIMARY],[PRIMARY],[PRIMARY],[PRIMARY],[PRIMARY]);

CREATE TABLE tblPartitionByCntry( memberId int PRIMARY KEY
identity(1,1), cntryId int, txt1 varchar(100), txt2 varchar(100), txt3
varchar(100), txt4 varchar(100) ) ON PartitionSchemeByCntry(cntryId);
  

Msg 1908,Level 16,State 1,Line 16 Column' cntryId'是分区   索引的列' PK__tblPartitionByCn__0880433F'。划分   唯一索引的列必须是索引键的子集。消息   1750,等级16,状态0,行16无法创建约束。看到   以前的错误。

如何在非主键上进行分区?

1 个答案:

答案 0 :(得分:0)

尝试创建以使用主键创建分区方案后将其应用于表格,如下所示。

CREATE TABLE [DBO].[RowTrip] 
(
  [id] [int] NOT NULL,
  [Season] [int] NOT NULL,
  [Distance] [decimal] not null
  CONSTRAINT [PK_TBL_ROWTRIP] PRIMARY KEY CLUSTERED (id ASC)
)
GO

CREATE INDEX [CI_ROWTRIP_BY_SEASON] ON [dbo].[RowerTrip]
(
    [Season]
) ON [PS_BY_SEASON]([Season])

PS_BY_SEASON是你的:PartitionSchemeByCntry