zoukankan      html  css  js  c++  java
  • sql server2008 表分区

    1、单表达多少条数据后需要分区呢?
       a.个人认为要似情况而定,有些常操作的表,分区反而带来麻烦,可以采用物理分表以及其它方法处理;
       b.对于一些日志、历史订单类的查询数据,500w左右即可享受分区带来的优越性;

       c.可以将分区映射到文件组,每个分区访问一个不同的物理磁盘驱动器,以便提高 I/O 性能
      
    2、sql server 2008 中怎么分呢?
       a.选中要分区的表(右击)->存储->创建分区->选择分区列(一般采用时间字段分区)->输入分区函数名->输入分区方案名->选择边界值
       b.如下图:
      

       

       

       

       

       

    3、sql server 2005 中怎么分呢?  

    -- 1、CREATE PARTITION FUNCTION意思是创建一个分区函数。2、partfunSale为分区函数名称。3、AS RANGE RIGHT为设置分区范围的方式为Right,也就是右置方式。4、FOR VALUES ('20100101','20110101','20120101','20130101')为按这几个值来分区。
    CREATE PARTITION FUNCTION YearCustomerFollowFunction(fDate) AS RANGE RIGHT FOR VALUES('20100101','20110101','20120101','20130101')  
    
    -- 分区方案的作用是将分区函数生成的分区映射到文件组中去。分区函数的作用是告诉SQL Server,如何将数据进行分区,而分区方案的作用则是告诉SQL Server将已分区的数据放在哪个文件组中
    CREATE PARTITION SCHEME YearCustomerFollow AS PARTITION YearCustomerFollowFunction TO(Sale2009,Sale2010,Sale2011,Sale2012,Sale2013)  
    
    -- 创建分区表 ON YearCustomerFollow 分区方案名
    CREATE TABLE t_CustomerFollow_history([Id] [int] IDENTITY(1,1) NOT NULL, [Name] [varchar](16) NOT NULL, [fDate][datetime] NOT NULL) ON YearCustomerFollow([fDate])  
    
    -- 删除一个分区
    ALTER PARTITION FUNCTION YearCustomerFollowFunction() MERGE RANGE ('20100101')
    
    -- 添加一个分区
    ALTER PARTITION SCHEME YearCustomerFollow NEXT USED [Sale2010]     -- 分区方案
    ALTER PARTITION FUNCTION YearCustomerFollowFunction() SPLIT RANGE ('20100101')  -- 分界值
    
      
    -- 查询所有分区编号及记录数
    select $PARTITION.YearCustomerFollowFunction(fDate) as 分区编号,count(id) as 记录数 from t_Customerfollow_histroy group by $PARTITION.YearCustomerFollowFunction(fDate)    
    

    4、怎么使用呢?
    --创建分区索引
     create index ix_fdate ON t_Customerfollow_histroy(fDate) ON YearCustomerFollow(fDate)
     

    -- 查询数据比较,如下:查询  '2008-01-01'  到  '2009-01-01' 之间的数据
     select * from t_Customerfollow_histroy where fDate > '2008-01-01' and fDate < '2009-01-01'

    -- 因为直接被分区到第9个区域中,固如下查询即可直接查询出  '2008-01-01'  到  '2009-01-01' 之间的数据

    select * from t_Customerfollow_histroy where $partition.YearCustomerFollowFunction(fDate)=9


      

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    unity3d工具栏介绍
    初识unity3d
    js模拟表单提交
    配置Appium环境
    html单选框 bootstrap模态框里面的单选框 和jq取值
    解决输入框总被浏览器记住的记录遮挡住的问题
    U盘
    python 字典列表/列表套字典 去重重复的字典数据
    ajax把数据return出去
    js把列表转换成字符串
  • 原文地址:https://www.cnblogs.com/buysingoo/p/4780510.html
Copyright © 2011-2022 走看看