Solved

Error creating a Clustered Primary Key on a partition table

Posted on 2011-09-22
4
396 Views
Last Modified: 2012-05-12
I have a table that has been designed, ready to go into production and loaded up with data and I need to partition it for performance reasons. But I'm getting an error.  I need to be able to partition on a column that is not part of the clustered primary key, can this be done.  thanks in advance for your help.

table definiition before partitioning......................
CREATE TABLE [test].PartyTextDetail](
      [PublishDateTime] [datetime] NOT NULL,
      [PartySK] [int] NOT NULL,
      [AttributeSK] [int] NOT NULL,
      [AsOfDateTime] [datetime] NOT NULL,
      [NextPublishDateTime] [datetime] NOT NULL,
      [NextAsOfDateTime] [datetime] NOT NULL,
      [AttributeValue] [nvarchar](255) NOT NULL,
      [ProcessGUID] [uniqueidentifier] NOT NULL,
      [CurrentRecordInd] [bit] NOT NULL,
 CONSTRAINT [PKPartyTextDetail] PRIMARY KEY CLUSTERED
(      [PublishDateTime] ASC,
      [PartySK] ASC,
      [AttributeSK] ASC,
      [AsOfDateTime] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

And this is the sql to create it as a partition table....
CREATE TABLE [test].[PartyTextDetail](
      [PublishDateTime] [datetime] NOT NULL,
      [PartySK] [int] NOT NULL,
      [AttributeSK] [int] NOT NULL,
      [AsOfDateTime] [datetime] NOT NULL,
      [NextPublishDateTime] [datetime] NOT NULL,
      [NextAsOfDateTime] [datetime] NOT NULL,
      [AttributeValue] [nvarchar](255) NOT NULL,
      [ProcessGUID] [uniqueidentifier] NOT NULL,
      [CurrentRecordInd] [bit] NOT NULL,
 CONSTRAINT [PKPartyTextDetail] PRIMARY KEY CLUSTERED
(      [PublishDateTime] ASC,
      [PartySK] ASC,
      [AttributeSK] ASC,
      [AsOfDateTime] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON
) ON PS_WEEKLY(NextAsOfDateTime))

And this is the error message I'm getting...
Msg 1908, Level 16, State 1, Line 2
Column 'NextAsOfDateTime' is partitioning column of the index 'PKPartyTextDetail'. Partition columns for a unique index must be a subset of the index key.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
0
Comment
Question by:partyon
  • 2
  • 2
4 Comments
 
LVL 42

Expert Comment

by:dqmq
ID: 36581545
>I need to be able to partition on a column that is not part of the clustered primary key, can this be done.

No
0
 

Author Comment

by:partyon
ID: 36582379
Is this just something that is just not done or is there a workaround to achive what I'm trying to do?
0
 
LVL 42

Accepted Solution

by:
dqmq earned 250 total points
ID: 36584907
Partitioning and the clustered index work hand-in-hand.  You can't partition, in the SQL Server sense, without involving the clustered index.

The only workaround of which I'm aware would be to implement a crude form of "home-grown" partitioning. For example, suppose you want to spllit your data into a different table for each  year.  Use stored procedures to evaluate the year and insert/update/delete from the appropriate table.  Use a view that joins all tables to retrieve the data.  
0
 

Author Closing Comment

by:partyon
ID: 36710869
thanks, after much discussion with the business I was able to add the partition key to the primary key. I appreciate your help.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now