oracle 入门笔记---分区表的分区交换
本文参考来自作者:蓝紫
详细内容请阅读原文 : http://www.cnblogs.com/lanzi/archive/2013/01/24/2875838.html
在oracle 11.2环境下测试
--drop table tab_a purge;
--创建分区表
create table tab_a
(
r_id number(19) primary key,
r_name varchar2(300),
r_pat integer
)
partition by list (r_pat)
(
partition p_value1 values(1),
partition p_value2 values(2),
partition p_value3 values(3),
partition p_def values(default)
)
;
--创建普遍表
create table tab_b as select * from tab_a;
--创建主键
alter table tab_b add primary key(r_id);
---插入测试数据
insert into tab_a
(r_id,r_name,r_pat)
select a.OBJECT_ID,a.OBJECT_NAME,1 from all_objects a;
insert into tab_a select 99199999,'test',1 from dual;
commit;
--测试分区交换
----1.分区表,创建了主键索引,普通表没有创建,则
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation
--ORA-14097: ALTER TABLE EXCHANGE PARTITION 中的列类型或大小不匹配
---2.分区表,创建了主键索引,普通表也创建全局索引则
alter table tab_b add primary key(r_id);
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation update global indexes;
--ORA-14098: ALTER TABLE EXCHANGE PARTITION 中的表索引不匹配
--3.分区表,创建了主键索引,普通表也创建主键索引则,且不包含索引交换
alter table tab_a exchange partition p_value1 with table tab_b /*including indexes*/ without validation /*update global indexes*/;
--成功---
--但是 insert into tab_a select 99199999,'test',1 from dual;
--ORA-01502: 索引 'SCOTT.SYS_C0012090' 或这类索引的分区处于不可用状态
---这时需要重建索引才能更新数据 ----
alter index SCOTT.SYS_C0012090 rebuild;
insert into tab_a select 99399999,'test',1 from dual;
---成功,,,
--4.分区表,创建了主键索引,普通表也创建主键索引则,且不包含索引交换,更新全局索引
truncate table tab_a;(/*清理分区不行*/)
insert into tab_a select 99199999,'test',1 from dual;
commit;
alter table tab_a exchange partition p_value1 with table tab_b /*including indexes*/ without validation update global indexes;
insert into tab_a select 99399999,'test',1 from dual;
---成功,,,
---但是更新普通表数据时,insert into tab_b select 99399999,'test',1 from dual 时,
--ORA-01502: 索引 'SCOTT.SYS_C0012090' 或这类索引的分区处于不可用状态
--------------------------
---5.在分区表的非分区表键上建立全局索引,普通表也建立全局索引
alter table tab_a drop primary key;
alter table tab_b drop primary key;
create index idx_a_r_id on tab_a(r_id) ;
create index idx_b_r_id on tab_b(r_id) ;
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;
-----ORA-14098: ALTER TABLE EXCHANGE PARTITION 中的表索引不匹配
---6.在分区表的非分区表键上建立全局索引,普通表不建立全局索引
drop index idx_b_r_id;
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;
---成功
-----7.在分区表的非分区键上建立本地索引,普通表不创建索引
drop index idx_a_r_id;
create index idx_a_r_id on tab_a(r_id) local;
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;
--ORA-14098: ALTER TABLE EXCHANGE PARTITION 中的表索引不匹配
-----8.在分区表的非分区键上建立本地索引,普通表创建索引
create index idx_b_r_id on tab_b(r_id) ;
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;
---成功
---9.在分区表的分区键上创建全局索引,普通表创建索引
drop index idx_a_r_id;
drop index idx_b_r_id;
create index idx_a_r_pat on tab_a(r_pat) ;
create index idx_b_r_pat on tab_b(r_pat) ;
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;
--ORA-14098: ALTER TABLE EXCHANGE PARTITION 中的表索引不匹配
---10.在分区表的分区键上创建全局索引,普通表不创建索引
drop index idx_a_r_pat;
drop index idx_b_r_pat;
create index idx_a_r_pat on tab_a(r_pat) ;
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;
---成功
-----11.在分区表的分区键上创建本地索引,普通表不创建索引
drop index idx_a_r_pat;
create index idx_a_r_pat on tab_a(r_pat) local;
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;
--ORA-14098: ALTER TABLE EXCHANGE PARTITION 中的表索引不匹配
----12.在分区表的分区键上创建本地索引,普通表创建索引
create index idx_b_r_pat on tab_b(r_pat) ;
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;
---成功
---
---13.在分区表上的分区键和非分区键上创建全局索引,普通表上创建索引
drop index idx_a_r_id;
drop index idx_b_r_id;
create index idx_a_r_id on tab_a (r_id,r_pat);
create index idx_b_r_id on tab_b (r_id,r_pat);
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;
--报错
---14.在分区表上的分区键和非分区键上创建全局索引,普通表不创建索引
drop index idx_b_r_id;
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;
---成功
--15.在分区表上的分区键和非分区键上创建本地索引,普通表不创建索引
drop index idx_a_r_id;
create index idx_a_r_id on tab_a(r_id,r_pat) local;
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;
---报错
--16.在分区表上的分区键和非分区键上创建本地索引,普通表创建索引
create index idx_b_r_id on tab_b(r_id,r_pat) ;
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;
---成功
---17.在分区表上的分区键和非分区键上创建本地索引a,同时又在非分区键上创全局建索引b,普通表对应字段上都创建索引
drop index idx_a_r_id;
drop index idx_b_r_id;
create index idx_a_r_id on tab_a(r_id);
create index idx_b_r_id on tab_b(r_id);
create index idx_a_r_id_loc on tab_a(r_id,r_pat) local;
create index idx_b_r_id_loc on tab_b(r_id,r_pat) ;
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;
--报错
---18.在分区表上的分区键和非分区键上创建本地索引a,同时又在非分区键上创建全局索引b,
--在普通表对应的分区表上的本地索引a的字段上创建索引,同时分区表的全局索引对应的字段上不创建索引
drop index idx_a_r_id;
drop index idx_b_r_id;
drop index idx_a_r_id _loc;
drop index idx_b_r_id _loc;
create index idx_a_r_id on tab_a(r_id);
create index i idx_a_r_id_loc on tab_a (r_id,r_pat) local;
create index idx_b_r_id _loc on tab_b (r_id,r_pat) ;
alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;
--成功
----以上创建普通表的索引时,都是跟分区表的字段相对应
oracle 入门笔记---分区表的分区交换的更多相关文章
- Oracle入门笔记 ——启动进阶
1.2 进阶内容: 两个概念:SCN 和 检查点 1.SCN的定义: system change member ,系统改变号,是数据库中非常重要的一个数据结构. SCN 用以标示数据 ...
- Oracle入门笔记 ——启动
参考教材<深入浅出Oracle> 兴趣 + 勤奋 + 坚持 + 方法 ≍ 成功 DBA生存之四大守则 1.备份重于一切: 2.三思而后行: 3.rm是危险的: 4.你来制定规范: 第一章: ...
- oracle 入门笔记--v$sql和v$sqlarea视图(转载)
转载于作者:dbtan 原文链接:http://www.dbtan.com/2009/12/vsql-and-vsqlarea-view.html v$sql和v$sqlarea视图: 上文提到,v$ ...
- oracle分区交换技术
交换分区的操作步骤如下: 1. 创建分区表t1,假设有2个分区,P1,P2.2. 创建基表t11存放P1规则的数据.3. 创建基表t12 存放P2规则的数据.4. 用基表t11和分区表T1的P1分区交 ...
- 【三思笔记】 全面学习Oracle分区表及分区索引
[三思笔记]全面学习Oracle分区表及分区索引 2008-04-15 关于分区表和分区索引(About PartitionedTables and Indexes) 对于 10gR2 而言,基本上可 ...
- Oracle用分区表分区交换做历史数据迁移
一. 说明: OLTP库中有些表数据量大,且每月有持续的大量数据添加.因为历史数据在此库中不再做訪问,而是在另1个OLAP库中做分析.所以会对历史数据迁移至OLAP库中.对这样的历史数据迁移的操作.较 ...
- 深入学习Oracle分区表及分区索引
关于分区表和分区索引(About Partitioned Tables and Indexes)对于10gR2而言,基本上可以分成几类: • Range(范围)分区 • Has ...
- oracle 分区表和分区索引
很复杂的样子,自己都没有看完,以备后用 http://hi.baidu.com/jsshm/item/cbfed8491d3863ee1e19bc3e ORACLE分区表.分区索引ORACLE对于分区 ...
- ORACLE分区表、分区索引详解
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt160 ORACLE分区表.分区索引ORACLE对于分区表方式其实就是将表分段 ...
随机推荐
- 【Swift】学习笔记(二)——基本运算符
运算符是编程中用得最多的,其包含一元,二元和三元 三种运算符.swift也和其他编程语言一样基本就那些,以下总结一下,也有它特有的运算符.比方区间运算符 1.一元运算符 = 赋值运算符,用得最多的 ...
- Java后端发出post请求带参数并接收返回的json
核心代码: 参数格式: “key1=value1&key2=value2” /*** sendUrl (远程请求的URL)* param (远程请求参数)* JSONObject ...
- C++中UINT32和INT32以及int,BOOL和bool的差别
在AndroidHAL层开发中,编写C++代码的时候.遇到了数据类型的困扰.经过查找资料,总结例如以下: 1.UNIT32和int以及INT32的差别: (1).int默认是signed int.也就 ...
- bootrap 手风琴Collapse源码分析
/* ======================================================================== * Bootstrap: collapse.js ...
- Linux/Android——Input系统之frameworks层InputManagerService (六)【转】
本文转载自:http://blog.csdn.net/u013491946/article/details/72638954 版权声明:免责声明: 本人在此发文(包括但不限于汉字.拼音.拉丁字母)均为 ...
- sql compare options
sql compare project's options Add object existence checks Use DROP and CREATE instead of ALTER Ignor ...
- 利用JFreeChart生成多轴图表(7) (转自 JSP开发技术大全)
利用JFreeChart生成多轴图表(7) (转自 JSP开发技术大全) 14.7 利用JFreeChart生成多轴图表 通过JFreeChart插件还可以生成拥有多个坐标轴的图表,简称多轴图表.在生 ...
- ViewPager嵌套ViewPager后子ViewPager滑动不正常问题
ViewPager嵌套ViewPager后,滑动事件没法在子ViewPager里面响应. 解决办法是自定义子ViewPager. 以下代码是转载的,经本人测试,可以用!!! 转载地址:http://b ...
- luogu 1121 环状最大两段子段和
题目大意: 一个序列看做一个环 选两段数使它们和最大 思路: 定义一个dp数组i j 0/1 表示前i个取了连续的j段 0/1表示取不取第i个 但是因为看做一个环 首尾相接的情况可以看做是选三段,其中 ...
- nginx配置改变默认访问路径
在安装完nginx服务后,url访问的默认路径是安装的路径html文件夹下的内容,如果需要指定自定义的路径,需要配置nginx.conf文件内容,这样通过url访问就可以了,比如: http://12 ...