zoukankan      html  css  js  c++  java
  • Oracle表分区

    自从oracle8i 开始可以把一个表分割为多个小的部分,这样可以对oracle的性能优化带来很大的好处~
    例如:改善表的查询性能,更加容易管理表数据,备份和恢复操作更方便

    在oracle 中分区表 分为好几种的(范围分区,散列分区,子分区,列表分区,索引分区)下面我们来慢慢介绍

    现在我们来建立一个[范围分区]
    create table RangeTable(
     id int primary key,
     name varchar(20),
     grade int
    )
    partition by rang(grade)
    (
     partition part1 values less then(50) tablespace Part1_tb,
     partition part2 values less then(MAXVALUE) tablespace Part2_tb
    );
    如果grade的值小于50的话 就把记录放到名为part1的分区当中,part1分区将被存储在Part1_tb表空间中
    其他的就放在part2中 MAXVALUE是oracle的关键字 表示最大值

    [散列分区]
    create table HashTable(
     id int primary key,
     name varchar(20),
     grade int
    )
    /*有两种方式,1就是指定分区数目和所使用的表空间,2指定以命名的分区*/
    partition by hash(grade)
    partitions 10 -- 指定分区的数目
    store in(Part1_tb,Part2_tb,Part3_tb) --如果指定的分区数目比表空间多,分区会以循环方式分配到表空间
    /*------------------------------------*/
    partition by rang(grade)--这种方式就是 指定以命名的分区
    (
     partition part1 tablespace Part1_tb,
     partition part2 tablespace Part2_tb
    );

    [子分区]即是分区的分区
    create table ChildTable(
     id int primary key,
     name varchar(20),
     grade int
    )
    partition by rang(grade)
    subpartition by hash(grade)
    partitions 5
    (
     partition part1 values less then(30) tablespace Part1_tb,
     partition part2 values less then(60) tablespace Part2_tb,
     partition part3 values less then(MAXVALUE) tablespace Part3_tb
    );

    [列表分区]告诉oracle所有可能的值
    create table ListTable(
     id int primary key,
     name varchar(20),
     area varchar(10)
    )
    partition by list(area)
    (
     partition part1 values('guangdong','beijing') tablespace Part1_tb,
     partition part2 values('shanghai','nanjing') tablespace Part2_tb
    );

    [索引分区]索引也可以按照和表进行分区时使用的相同的值范围来分区
    create index IndexTable_index
    on IndexTable(name)
    local
    (
     partition part1 tablespace Part1_tb,
     partition part2 tablespace Part2_tb
    )
    --local 告诉oracle表 IndexTable的每一个分区建立一个独立的索引
    create index IndexTable_index
    on IndexTable(name)
    global;
    --global为全局索引 全局索引可以包含多个分区的值 局部索引比全局索引容易管理,而全局索引比较快
    注意:不能为散列分区 或者 子分区创建全局索引

    查询某一个表分区
    select * from table partition(part1);

    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/kj021320/archive/2006/08/18/1095924.aspx

  • 相关阅读:
    谷歌浏览器解决跨域
    实现Linux共享Window文件
    linux安装显卡驱动
    jsduck 文档生成器
    linux 笔记
    Linux phpstorm 无法输入中文
    linux 安装composer
    Extjs动态生成表头(适用报表)
    关于git的配置与使用
    JSP解决中文乱码问题
  • 原文地址:https://www.cnblogs.com/linsond/p/1543807.html
Copyright © 2011-2022 走看看