zoukankan      html  css  js  c++  java
  • Partition--分区切换

    现有数据表[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]
     
     
     
     
  • 相关阅读:
    谈谈程序员、技术主管和架构师
    PyPI教程
    python以下划线开头的变量和函数的作用
    csv和xlsx区别
    编码问题2 utf-8和Unicode的区别
    编码问题1
    洛谷 1404 平均数
    洛谷 1441 砝码秤重
    【模板】高斯消元法
    线段树练习题
  • 原文地址:https://www.cnblogs.com/TeyGao/p/3520450.html
Copyright © 2011-2022 走看看