Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Partitioning - Unique Index Error

I have a table that is partitioned by TRANSACTION_DATE_TIME.

Table has a column: ID.

I want to create a unique index for ID on partition scheme as:

CREATE UNIQUE NONCLUSTERED INDEX [IX_ID_ON_PS_DATETIME] ON [CRD].[TRANSACTION] 
(
    [ID] ASC
) ON [PS_DATETIME_WEEKLY]([TRANSACTION_DATE_TIME])

but SQL says "Partition column for a unique index must be a subset of index key".

I really don't need TRANSACTION_DATE_TIME column in this index.

How can I create the index without using TRANSACTION_DATE_TIME column?

like image 701
Ahmet Altun Avatar asked Jan 03 '12 09:01

Ahmet Altun


1 Answers

You have two choices: you create a NON-partitioned index, or you MUST include the partitioning key in a partitioned index:

  • Non-partitioned index

    CREATE UNIQUE NONCLUSTERED INDEX [IX_ID_ON_PS_DATETIME] ON [CRD].[TRANSACTION] 
    (
        [ID] ASC
    ) ON PRIMARY
    

OR

  • Partitioned index that includes the partitioning key

    CREATE UNIQUE NONCLUSTERED INDEX [IX_ID_ON_PS_DATETIME] ON [CRD].[TRANSACTION] 
    (
        [ID] ASC,
        TRANSACTION_DATE_TIME
    ) ON [PS_DATETIME_WEEKLY]([TRANSACTION_DATE_TIME])
    
like image 57
Oleg Dok Avatar answered Sep 18 '22 07:09

Oleg Dok