现有数据表[dbo].[staging_TB1_20131018-104722]和分区表[dbo].[TB1],需要将分区表和数据表中做数据交换 CREATE TABLE [dbo].[staging_TB1_20131018-104722]( [C1] [int] NOT NULL, [C2] [nvarchar](200) NULL, [C3] [nvarchar](200) NULL, [PID] [bigint] NOT NULL ) ON [PRIMARY] GO ALTER TABLE [dbo].[staging_TB1_20131018-104722] WITH CHECK ADD CONSTRAINT [chk_staging_TB1_20131018-104722_partition_496] CHECK (([PID]>N'495000' AND [PID]<=N'496000')) GO ALTER TABLE [dbo].[staging_TB1_20131018-104722] CHECK CONSTRAINT [chk_staging_TB1_20131018-104722_partition_496] GO CREATE TABLE [dbo].[TB1]( [C1] [int] IDENTITY(1,1) NOT NULL, [C2] [nvarchar](200) NULL, [C3] [nvarchar](200) NULL, [PID] [bigint] NOT NULL ) GO CREATE UNIQUE CLUSTERED INDEX [CI_PID_CI] ON [dbo].[TB1] ( [C1] ASC, [PID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON pf_Test([C1]) GO ------------------------------------------------------------------------------------------------------------------------------------------------------ 查找分区表的对应的分区ID SELECT $PARTITION.pf_Test(496000) 将数据表数据导入到分区表中 ALTER TABLE [dbo].[staging_TB1_20131018-104722] SWITCH TO [dbo].[TB1] PARTITION 496 将分区表中数据导入到数据表 ALTER TABLE [dbo].[TB1] SWITCH PARTITION 496 TO [dbo].[staging_TB1_20131018-104722]