• SQL code for the partitoned example


    --
    --Chapter 12 SQL code for the partitoned example.
    --
     
    USE AdventureWorks2008;

    -- Create the partition function
    CREATE PARTITION FUNCTION [OrderDateRangePFN](datetime)
    AS RANGE RIGHT
    FOR VALUES (N'2001-01-01 00:00:00', N'2002-01-01 00:00:00',
    N'2003-01-01 00:00:00', N'2004-01-01 00:00:00');


    -- Create the partition scheme
    CREATE PARTITION SCHEME [OrderDatePScheme]
    AS PARTITION [OrderDateRangePFN]
    TO ([Primary], [Primary], [Primary], [Primary], [Primary]);


    -- Create two tables: SalesOrderHeader is the partitioned table and SalesOrderHeaderOLD is the non-partitioned table

    CREATE TABLE [dbo].[SalesOrderHeader](
     [SalesOrderID] [int] NULL,
     [RevisionNumber] [tinyint] NOT NULL,
     [OrderDate] [datetime] NOT NULL,
     [DueDate] [datetime] NOT NULL,
     [ShipDate] [datetime] NULL,
     [Status] [tinyint] NOT NULL
    ) ON [OrderDatePScheme]([OrderDate]);

    CREATE TABLE [dbo].[SalesOrderHeaderOLD](
     [SalesOrderID] [int] NULL,
     [RevisionNumber] [tinyint] NOT NULL,
     [OrderDate] [datetime] NOT NULL  ,
     [DueDate] [datetime] NOT NULL,
     [ShipDate] [datetime] NULL,
     [Status] [tinyint] NOT NULL);

    -- Load daata into the partitioned table
    INSERT INTO SalesOrderHeader
    SELECT [SalesOrderID],[RevisionNumber], [OrderDate],[DueDate],[ShipDate],[Status] FROM SALES.[SalesOrderHeader];

    CREATE CLUSTERED INDEX SalesOrderHeaderCLInd
    ON SalesOrderHeader(OrderDate) ON OrderDatePScheme(OrderDate);

    CREATE CLUSTERED INDEX SalesOrderHeaderOLDCLInd ON SalesOrderHeaderOLD(OrderDate);

    ALTER  TABLE [DBO].[SalesOrderHeaderOLD]  WITH CHECK  ADD CONSTRAINT [CK_SalesOrderHeaderOLD_ORDERDATE] CHECK  ([ORDERDATE]>=('2003-01-01 00:00:00') AND [ORDERDATE]<('2004-01-01 00:00:00'));

    -- Verify data in the partitioned table
    SELECT $partition.OrderDateRangePFN(OrderDate) AS 'Partition Number' ,min(OrderDate) AS 'Min Order Date' , max(OrderDate) AS 'Max Order Date',count(*) AS 'Rows In Partition'
    FROM SalesOrderHeader
    GROUP BY $partition.OrderDateRangePFN(OrderDate);


    -- Switch the data from partition 4 into the SalesOrderHeaderOLD table
    ALTER TABLE SalesOrderHeader
    SWITCH PARTITION 4 TO SalesOrderHeaderOLD;


    -- Switch the data from SalesOrderHeaderOLD back to partition 4
    ALTER TABLE SalesOrderHeaderOLD   
    SWITCH TO SalesOrderHeader PARTITION 4;


    --To merge a partition range
    ALTER PARTITION FUNCTION OrderDateRangePFN()
    MERGE RANGE ('2003-01-01 00:00:00');



    -- To split a partition range
    ALTER PARTITION SCHEME OrderDatePScheme NEXT USED [Primary];
    ALTER PARTITION FUNCTION OrderDateRangePFN()
    SPLIT RANGE ('2003-01-01 00:00:00');

  • 相关阅读:
    Dispose() C# 优化内存
    C#对图片文件的压缩、裁剪操作初探
    C#如何调用COM
    rtf格式的一些说明,转载的
    IStream 接口
    NET RichTextBox控件如何可以插入图像
    AutoCAD如何打印
    AutoCAD如何编辑块,打散块
    AutoCAD菜单加载失败 找不到文件mnc 怎么办
    AE After Effect 渲染如何输出设置
  • 原文地址:https://www.cnblogs.com/shihao/p/2511940.html
Copyright © 2020-2023  润新知