Solved

Error creating a Clustered Primary Key on a partition table

Posted on 2011-09-22
4
394 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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 …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

11 Experts available now in Live!

Get 1:1 Help Now