Solved

Error creating a Clustered Primary Key on a partition table

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

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…
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

861 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

24 Experts available now in Live!

Get 1:1 Help Now