2017-05-04 55 views
0

當我試圖創建非主鍵列的表分區它得到一個錯誤:分區在SQL Server非主鍵列的表

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' is partitioning column of the index 'PK__tblPartitionByCn__0880433F'. Partition columns for a unique index must be a subset of the index key. Msg 1750, Level 16, State 0, Line 16 Could not create constraint. See previous errors.

如何使分區非主鍵?

回答

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