Oracle PL/SQL之Flashback Table與外鍵約束

來源:互聯網
上載者:User

我們知道 Flashback Table可以把drop掉的表從資源回收筒裡恢複回來,但是並不是關於該表的所有東西都能被Flashback回來,比如外鍵約束。

duzz$scott@orcl>create table d(deptno number primary key, deptname varchar2(20));</p><p>Table created.</p><p>Elapsed: 00:00:00.28<br />duzz$scott@orcl>create table e(empno number primary key, ename varchar2(20), deptno number, constraint fk_dept foreign key (deptno) references d(deptno));</p><p>Table created.</p><p>Elapsed: 00:00:00.39<br />duzz$scott@orcl>select * from d;</p><p> DEPTNO DEPTNAME<br />---------- -----------<br /> 10 IT<br /> 20 HR</p><p>Elapsed: 00:00:00.03<br />duzz$scott@orcl>select * from e;</p><p> EMPNO ENAME DEPTNO<br />---------- ------------- ----------<br /> 1 KING 10<br /> 2 HARI 20</p><p>Elapsed: 00:00:00.00<br />duzz$scott@orcl>select constraint_name,constraint_type,table_name from user_constraints where table_name in ('D','E');</p><p>CONSTRAINT_NAME CON TABLE_NAME<br />-------------------- --- -------------<br />SYS_C005553 P D<br />SYS_C005554 P E<br />FK_DEPT R E</p><p>Elapsed: 00:00:00.00<br />duzz$scott@orcl>insert into e values(2,'COTT',10);<br />insert into e values(2,'COTT',10)<br />*<br />ERROR at line 1:<br />ORA-00001: unique constraint (SCOTT.SYS_C005554) violated</p><p>Elapsed: 00:00:00.01<br />duzz$scott@orcl>insert into e values(3,'ING',55);<br />insert into e values(3,'ING',55)<br />*<br />ERROR at line 1:<br />ORA-02291: integrity constraint (SCOTT.FK_DEPT) violated - parent key not found</p><p>Elapsed: 00:00:00.01<br />duzz$scott@orcl>drop table e;</p><p>Table dropped.</p><p>Elapsed: 00:00:00.09<br />duzz$scott@orcl>flashback table e to before drop;</p><p>Flashback complete.</p><p>Elapsed: 00:00:00.10<br />duzz$scott@orcl>select constraint_name,constraint_type,table_name from user_constraints where table_name in ('D','E');</p><p>CONSTRAINT_NAME CON TABLE_NAME<br />-------------------- --- ---------------<br />SYS_C005553 P D<br />BIN$MzYoteesSWeEWRlJ P E<br />Afkfcg==$0</p><p>Elapsed: 00:00:00.00<br />duzz$scott@orcl>insert into e values(2,'COTT',10);<br />insert into e values(2,'COTT',10)<br />*<br />ERROR at line 1:<br />ORA-00001: unique constraint (SCOTT.BIN$MzYoteesSWeEWRlJAfkfcg==$0) violated</p><p>Elapsed: 00:00:00.01<br />duzz$scott@orcl>insert into e values(3,'ING',55);</p><p>1 row created.</p><p>Elapsed: 00:00:00.00<br />duzz$scott@orcl><br />

除此之外,帶有細粒度審計(Fine-Grained Auditing )和虛擬專用資料庫策略(Virtual Private Database policies)的表也不可恢複的哦,請看Oracle官方的Flashback說明:

  • A table and all of its dependent objects (indexes, LOB segments, nested tables, triggers, constraints and so on) go into the recycle bin together, when you drop the table. Likewise, when you perform Flashback Drop, the objects are generally all retrieved together.

    It is possible, however, that some dependent objects such as indexes may have been reclaimed due to space pressure. In such cases, the reclaimed dependent objects are not retrieved from the recycle bin.

  • Due to security concerns, tables which have Fine-Grained Auditing (FGA) and Virtual Private Database (VPD) policies defined over them are not protected by the recycle bin.

  • Partitioned index-organized tables are not protected by the recycle bin.

  • The recycle bin does not preserve referential constraints on a table (though other constraints will be preserved if possible). If a table had referential constraints before it was dropped (that is, placed in the recycle bin), then re-create any referential constraints after you retrieve the table from the recycle bin with Flashback Drop.

    REF:

    http://download.oracle.com/docs/cd/B19306_01/backup.102/b14192/flashptr004.htm

     

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.