I have a table partitioned by month. There are no primary key. There is another table with the same structure that I use to load data for the current month. I can perform partition switch with no problem.
I created non unique index on integer field in both tables. After this change partition switch does not work anymore. Here is an error that I am getting:
'ALTER TABLE SWITCH' statement failed. The table 'dbo.test' is
partitioned while index 'IX_test' is not partitioned."
Any help

partition switch and non unique index
KFrostILEM
Thanks for response. I red the article. Seems the problem is that my index is not aligned with the table. How to make it aligned Here is an index that I use for the source table. Partitioned table has simular index on [ACCTKEY] column as well
CREATE
NONCLUSTERED INDEX [IX_T_MSB_Pseudo] ON [dbo].[T_MSB_Pseudo] ([ACCTKEY]
ASC)
WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]BinuJ
Dudley
It works! thanks
Shokino
chrisc12345
Hi Umachandar,
I read the article. Seems I do everything correctly but still get the error...
CREATE PARTITION FUNCTION [PF_Caldkey](int) AS RANGE RIGHT FOR VALUES (198, 199, 200)
CREATE PARTITION SCHEME [PS_Caldkey] AS PARTITION [PF_Caldkey] TO ([PRIMARY], [PRIMARY], [PRIMARY])
CREATE TABLE [dbo].[T_MSB](
[ACCTKEY] [bigint] NULL,
[CALDKEY] [int] NOT NULL,
ON [PS_Caldkey]([CALDKEY])
CREATE TABLE [dbo].[T_MSB_Pseudo](
[ACCTKEY] [bigint] NULL,
[CALDKEY] [int] NOT NULL,
) ON [PRIMARY]
CREATE NONCLUSTERED INDEX IX_T_MSB ON dbo.T_MSB
(
ACCTKEY
) ON PS_Caldkey(CALDKEY)
CREATE NONCLUSTERED INDEX IX_T_MSB_Pseudo ON dbo.T_MSB_Pseudo
(
ACCTKEY
) ON PS_Caldkey(CALDKEY)
--Create constraint for the current CALDKEY
ALTER TABLE [dbo].[T_MSB_Pseudo] WITH CHECK ADD CONSTRAINT [CK_T_MSB_Pseudo] CHECK([CALDKEY]=199)
--Partition switch
alter table T_MSB_Pseudo SWITCH TO T_MSB PARTITION $PARTITION.PF_Caldkey(199)
Msg 7733, Level 16, State 3, Line 1
'ALTER TABLE SWITCH' statement failed. The index 'IX_T_MSB_Pseudo' is partitioned while table 'rebar.dbo.T_MSB_Pseudo' is not partitioned.
FreddieCode
CREATE NONCLUSTERED INDEX [IX_T_MSB_Pseudo] ON [dbo].[T_MSB_Pseudo] (
[ACCTKEY]
ASC)
WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF)ON your_partition_scheme(<partition_columns>)
Dave Miles
what if i just drop my composite index from the table that needs to be switched
but maintain the partitioning index
Since the destination table has its own composite index
and a partioning index as well
logtorahul
I experience this also.
NozFx
Ok, I created index aligned to partitioned schema on source and target tables. I am getting the error that my source table is not partitioned. But its not supposed to be partitioned because it holds only one month of data
Msg 7733, Level 16, State 3, Line 10
'ALTER TABLE SWITCH' statement failed. The index 'IX_T_MSB_Pseudo' is partitioned while table 'rebar.dbo.T_MSB_Pseudo' is not partitioned.
markdrury
Hello,
Regading to your following statement, does filegroup has to be the same. If I want switch to a table with index partitioned, the partion table index filegroup cannot the same as the source table as the partion table's index need to be on the partion scheme. I run into problem when creating a partition table with its primary key (I want to partition primary key) on a partition scheme. But if I leaves it to [Primary] filegroup, I am able to switch. But I want primary key index also be partitioned. Can you please help out this Thanks
Ljhopkins
vkv
I have more questions.I use the following statement to create partion function and tables:
CREATE
PARTITION FUNCTION Party_PFN(int)AS
RANGE
LEFT FOR VALUES (0, 8588394)GO
CREATE
PARTITION SCHEME [Party_PScheme]AS
PARTITION
Party_PFN all TO ([PRIMARY])CREATE
TABLE [dbo].[Party_O]([PartyID] [int]
IDENTITY(1,1) NOT NULL,[FirstName] [varchar]
(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[LastName] [varchar]
(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[PhoneAreaCode] [varchar]
(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [Party_PK_O] PRIMARY KEY CLUSTERED(
[PartyID]
ASC)
WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY])
ON [PRIMARY]CREATE
TABLE [dbo].[Party_p]([PartyID] [int]
IDENTITY(1,1) NOT NULL,[FirstName] [varchar]
(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[LastName] [varchar]
(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[PhoneAreaCode] [varchar]
(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [Party_PK_P] PRIMARY KEY CLUSTERED(
[PartyID]
ASC)
WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY])
ON [Party_PScheme](PartyID)Question 1: When I check the property of Party_p table, why does it say partion is FALSE.
Question 2: I am able to SWITCH and SPLIT Party_p] table. But when I run
select
* from sys.partitions where object_name(object_id)='Party_P'It always show one row.Peter De
CREATE
NONCLUSTERED INDEX [IX_T_MSB_Pseudo1] ON [dbo].[T_MSB_Pseudo] ([ACCTKEY]
ASC)
WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF)ON
PS_CaldkeyI am getting error message when creating index aligned to partition scheme PS_CALDKEY:
Msg 2726, Level 16, State 1, Line 2
Partition function 'PF_Caldkey' uses 1 columns which does not match with the number of partition columns used to partition the table or index.
Andrew Mercer
CREATE NONCLUSTERED INDEX IX_T_MSB ON dbo.T_MSB
(
ACCTKEY
) ON PS_Caldkey(CALDKEY)
on ic.object_id = i.object_id and ic.index_id = i.index_id
where i.name= 'IX_T_MSB' and i.object_id = object_id('dbo.T_MSB')
The switch operation now fails because the index on your non-partitioned table has only one column. In fact, in your definition you are partitioning the index which is incorrect. You want to just specify the FILEGROUP directly in the index like:
CREATE NONCLUSTERED INDEX IX_T_MSB_Pseudo ON dbo.T_MSB_Pseudo
(
ACCTKEY
) ON PRIMARY
CREATE NONCLUSTERED INDEX IX_T_MSB_Pseudo ON dbo.T_MSB_Pseudo
(
ACCTKEY
)
INCLUDE (
CALDKEY
)
ON PRIMARY