Oracle PL/SQL之Flashback Table与外键约束

我们知道 Flashback Table可以把drop掉的表从回收站里恢复回来,但是并不是关于该表的所有东西都能被Flashback回来,比如外键约束。

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


除此之外,带有细粒度审计(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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值