我有两个表,如下所示,后面是一个用于存储存档数据的表。
CREATE TABLE [ERP].[Transaction](
[TransactionID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[TransactionDateTime] [datetime] NOT NULL,
[TransactionName] [int] NOT NULL,
[TransactionData] [xml] NOT NULL,
[AcknowledgementDateTime] [datetime] NULL,
[AcknowledgementCode] [int] NULL,
[AcknowledgementDescription] [nvarchar](max) NULL,
[TransactionGUID] [uniqueidentifier] NOT NULL,
[WorkCenter] [nvarchar](10) NULL,
CONSTRAINT [pkTransaction] PRIMARY KEY NONCLUSTERED
(
[TransactionID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
)
GO
ALTER TABLE [ERP].[Transaction] ADD CONSTRAINT [defTransactionTransactionGUID] DEFAULT (newid()) FOR [TransactionGUID]
GO

CREATE TABLE [ERP].[TransactionArchived](
[TransactionID] [int] IDENTITY(1,1) NOT NULL,
[TransactionDateTime] [datetime] NOT NULL,
[TransactionName] [int] NOT NULL,
[TransactionData] [xml] NOT NULL,
[AcknowledgementDateTime] [datetime] NULL,
[AcknowledgementCode] [int] NULL,
[AcknowledgementDescription] [nvarchar](max) NULL,
[TransactionGUID] [uniqueidentifier] NOT NULL,
[WorkCenter] [nvarchar](10) NULL
)
GO

我按如下方式进行了分区,并创建了索引来支持分区。
CREATE PARTITION FUNCTION PartitionXFaceDataByMonthPF ( DATETIME )
AS RANGE RIGHT FOR VALUES ( '2010-01-01', '2010-02-01', '2010-03-01', '2010-04-01', '2010-05-01', '2010-06-01', '2010-07-01', '2010-08-01', '2010-09-01', '2010-10-01', '2010-11-01', '2010-12-01',
'2011-01-01', '2011-02-01', '2011-03-01', '2011-04-01', '2011-05-01', '2011-06-01', '2011-07-01', '2011-08-01', '2011-09-01', '2011-10-01', '2011-11-01', '2011-12-01',
'2012-01-01', '2012-02-01', '2012-03-01', '2012-04-01', '2012-05-01', '2012-06-01', '2012-07-01', '2012-08-01', '2012-09-01', '2012-10-01', '2012-11-01', '2012-12-01',
'2013-01-01', '2013-02-01', '2013-03-01', '2013-04-01', '2013-05-01', '2013-06-01', '2013-07-01', '2013-08-01', '2013-09-01', '2013-10-01', '2013-11-01', '2013-12-01',
'2014-01-01', '2014-02-01', '2014-03-01', '2014-04-01', '2014-05-01', '2014-06-01', '2014-07-01', '2014-08-01', '2014-09-01', '2014-10-01', '2014-11-01', '2014-12-01',
'2015-01-01', '2015-02-01', '2015-03-01', '2015-04-01', '2015-05-01', '2015-06-01', '2015-07-01', '2015-08-01', '2015-09-01', '2015-10-01', '2015-11-01', '2015-12-01' ) ;
--Create the PARTITION SCHEME
CREATE PARTITION SCHEME PartitionXFaceDataByMonthPS AS PARTITION PartitionXFaceDataByMonthPF ALL TO ( [PRIMARY] ) ;

Index Creation
ALTER TABLE [ERP].[Transaction] DROP CONSTRAINT [pkTransaction] ;
ALTER TABLE [ERP].[Transaction] ADD CONSTRAINT [pkTransaction] PRIMARY KEY NONCLUSTERED ( [TransactionID] ASC ) ON [PRIMARY] ;
/****** Object: Index [idxTransactionDateTime] Script Date: 01/14/2016 15:53:28 ******/
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[ERP].[Transaction]') AND name = N'idxTransactionDateTime')
DROP INDEX [idxTransactionDateTime] ON [ERP].[Transaction] WITH ( ONLINE = OFF )
GO
CREATE CLUSTERED INDEX idxTransactionDateTime ON [ERP].[Transaction]( [TransactionDateTime] ) ON PartitionXFaceDataByMonthPS( [TransactionDateTime] ) ;
--DROP TABLE [ERP].[TransactionArchived] ; --This needs to execute only if we rerun the same set onace again on the same DB
SELECT * INTO [ERP].[TransactionArchived] FROM [ERP].[Transaction] WHERE 1 = 2 ;
CREATE CLUSTERED INDEX idxTransactionDateTime ON [ERP].[TransactionArchived] ( TransactionDateTime ) ON PartitionXFaceDataByMonthPS( [TransactionDateTime] ) ;
--CREATE NONCLUSTERED INDEX [pkTransaction] ON [ERP].[TransactionArchived] ( [TransactionID] ) ON PartitionXFaceDataByMonthPS( [TransactionDateTime] ) ;
GO

当我切换数据时,它会给出如下错误,我正在努力寻找解决方案。请帮忙
' ALTER TABLE SWITCH'声明失败了。该表' EPMSDataExchange.ERP.Transaction'在索引&#p; pkTransaction'没有分区。
感谢 PEP