Flashback table and foreign key constraints in Oracle PL/SQL

Source: Internet
Author: User

We know that the flashback table can restore the drop table from the recycle bin, but not everything about the table can be returned by flashback, such as foreign key constraints.

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 $ paip 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, 'in', 55); </P> <p> 1 row created. </P> <p> elapsed: 00:00:00. 00 <br/> duzz $ Scott @ orcl> <br/>

In addition, tables with fine-grained auditing and virtual private database policies cannot be recovered. Please refer to the official Oracle flashback description:

  • 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 ies 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

     

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.