聯機重定義(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;
/
 


發佈了178 篇原創文章 · 獲贊 12 · 訪問量 23萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章