• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

Oracle表分区学习笔记

发布: 2007-7-04 17:55 | 作者: admin | 来源:  网友评论 | 查看: 35次 | 进入软件测试论坛讨论

领测软件测试网

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);

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网