Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error creating a Clustered Primary Key on a partition table

Posted on 2011-09-22
4
Medium Priority
?
405 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 750 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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