联机重定义(Online Redefinition)浅析

--联机重定义(Online Redefinition)浅析


--用途:
1.Modify the storage parameters of a table or cluster
2.Move a table or cluster to a different tablespace
3.Add, modify, or drop one or more columns in a table or cluster
4.Add or drop partitioning support (non-clustered tables only)
5.Change partition structure
6.Change physical properties of a single table partition, including moving it to a different tablespace in the same schema
7.Change physical properties of a materialized view log or an Oracle Streams Advanced Queuing queue table
8.Add support for parallel queries
9.Re-create a table or cluster to reduce fragmentation
10.Convert a relational table into a table with object columns, or do the reverse.
11.Convert an object table into a relational table or a table with object columns, or do the reverse.
12.Change the organization of a normal table (heap organized) to an index-organized table, or do the reverse.



--重定义方法:
1.通过主键或伪主键
 For this method, the versions of the tables before and after redefinition should have the same primary key columns. 


2.通过rowid。
 In this method, a hidden column named M_ROW$$ is added to the post-redefined version of the table.
 You can then use the ALTER TABLE ... DROP UNUSED COLUMNS statement to drop it.

 You cannot use this method on index-organized tables.


--实验 
1.准备中间表
CREATE TABLE "SCOTT"."TMP"
 ("EMPNO" NUMBER(4,0),
"ENAME" VARCHAR2(10),
"JOB" VARCHAR2(9),
"MGR" NUMBER(4,0),
"HIREDATE" DATE,
"SAL" NUMBER(7,2),
"COMM" NUMBER(7,2),
"DEPTNO" NUMBER(2,0),
 CONSTRAINT "PK_EMP_EMPNO" PRIMARY KEY ("EMPNO"))
partition by range (deptno)
(partition p10 values less than (20) tablespace tbs1,
partition p20 values less than (30) tablespace tbs2,
partition p30 values less than (40) tablespace tbs3
);

select table_name,partition_name,tablespace_name from user_tab_partitions;

2.开始重定义 conn / as sysdba
begin
DBMS_REDEFINITION.START_REDEF_TABLE (
'SCOTT','EMP','TMP',
'EMPNO EMPNO,
ENAME ENAME,
JOB JOB,
MGR MGR,
HIREDATE HIREDATE,
SAL SAL,
COMM COMM,
DEPTNO DEPTNO');
end;
/

3.同步数据
begin
DBMS_REDEFINITION.SYNC_INTERIM_TABLE ('SCOTT','EMP','TMP');
end;
/

4.结束重定义
begin
DBMS_REDEFINITION.FINISH_REDEF_TABLE ('SCOTT','EMP','TMP');
end;
/
 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值