zoukankan      html  css  js  c++  java
  • 创建分区表,提高查询效率

    CREATE DATABASE Sales ON PRIMARY
    (
        NAME = N'Sales',
        FILENAME = N'd:\DATA\Sales.mdf',
        SIZE = 3MB,
        MAXSIZE = 100MB,
        FILEGROWTH =10%
        ),
        FILEGROUP FG1
        (
        NAME = N'File1',
        FILENAME = N'd:\DATA\File1.ndf',
        SIZE = 1MB,
        MAXSIZE = 100MB,
        FILEGROWTH = 10%
        ),
        FILEGROUP FG2
        ( 
        NAME = N'File2',
        FILENAME = N'd:\DATA\File2.ndf',
        SIZE = 1MB,
        MAXSIZE = 100MB,
        FILEGROWTH = 10%
        ),
        FILEGROUP FG3
        (
        NAME = N'File3',
        FILENAME = N'd:\DATA\File3.ndf',
        SIZE = 1MB,
        MAXSIZE = 100MB,
        FILEGROWTH = 10%
        )
     LOG ON 
     (
       NAME = N'Sales_Log',
       FILENAME = N'd:\DATA\Sales_Log.ndf',
       SIZE = 1MB,
       MAXSIZE = 100MB,
       FILEGROWTH = 10%
       )
        GO 
     
     ---------------------------------------------how 
     USE Sales
     GO 
     CREATE PARTITION FUNCTION pf_OrderDate(DATETIME)
     AS RANGE RIGHT
     FOR VALUES('2003/01/01', '2004/01/01') 
     GO
     
     ------------------------------ where 
     USE Sales 
     GO
     CREATE PARTITION SCHEME ps_OrderDate
     AS PARTITION pf_OrderDate
     TO (FG1,FG2, FG3)
     GO
     
     ------------------------------ create partion table -----
     USE Sales 
     GO
     CREATE TABLE dbo.Orders 
     (
        OrderID INT IDENTITY(10000,1),
        OrderDate DATETIME NOT NULL,
        CustomerID INT NOT NULL,
        CONSTRAINT PK_Orders PRIMARY KEY (OrderID, OrderDate)
     ) ON ps_OrderDate(OrderDate)
     
     GO
     CREATE TABLE dbo.OrdersHistory
     (
        OrderID INT IDENTITY(10000, 1),
        OrderDate DATETIME NOT NULL,
        CustomerID INT NOT NULL,
        CONSTRAINT PK_OrdersHistory PRIMARY KEY (OrderID, OrderDate)
        )ON ps_OrderDate(OrderDate)
        GO
        
     
     ----------------------------------------- Insert 2002 data --
     USE Sales 
     GO 
    INSERT INTO dbo.Orders (OrderDate, CustomerID) VALUES ('2002/6/25', 1000)    
    INSERT INTO dbo.Orders (OrderDate, CustomerID) VALUES ('2002/8/13', 1000)    
    INSERT INTO dbo.Orders (OrderDate, CustomerID) VALUES ('2002/8/25', 1000)    
    INSERT INTO dbo.Orders (OrderDate, CustomerID) VALUES ('2002/9/23', 1000) 
    GO 
    
    --------------------------------- Insert 2003 data ------------------
    USE Sales    
    GO 
    INSERT INTO dbo.Orders (OrderDate, CustomerID) VALUES ('2003/6/25', 1000) 
    INSERT INTO dbo.Orders (OrderDate, CustomerID) VALUES ('2003/8/13', 1000) 
    INSERT INTO dbo.Orders (OrderDate, CustomerID) VALUES ('2003/8/25', 1000) 
    INSERT INTO dbo.Orders (OrderDate, CustomerID) VALUES ('2003/9/23', 1000)    
    GO
    
    ------------------------ 归档数据 ------------------------------------
    USE Sales 
    GO
    ALTER TABLE dbo.Orders SWITCH PARTITION 1 TO dbo.OrdersHistory PARTITION 1
    GO 
    
    --------------------------- 添加新分区 --------------------------------
    
    USE Sales 
    GO 
    ALTER PARTITION SCHEME ps_OrderDate NEXT USED FG2 
    ALTER PARTITION FUNCTION pf_OrderDate() SPLIT RANGE('2006/01/01')
    GO 
    
    ----------------------------
    SELECT * FROM sys.partition_functions 
    SELECT * FROM sys.partition_range_values 
    SELECT * FROM sys.partition_schemes
    
    
    
    
    
    
    
    
    
    
    
     
     
     
    
     
     
     
     
  • 相关阅读:
    SpringMVC Failed to instantiate [java.util.List]: Specified class is an interface
    github上项目直接在浏览器页面像VS Code一样查看代码
    springboot+dubbo整合swagger-ui+swagger-dubbo
    petalinux非离线模式build卡死在u-boot编译问题
    SystemC使用示例
    使用chisel做数字电路开发的Hello World
    lmgrd在Linux系统上的配置
    FFmpeg libswscale源码分析3-scale滤镜源码分析
    FFmpeg libswscale源码分析2-转码命令行与滤镜图
    FFmpeg libswscale源码分析1-API介绍
  • 原文地址:https://www.cnblogs.com/tianjinquan/p/2566295.html
Copyright © 2011-2022 走看看