Oracle 在Drop表时的Cascade Constraints

http://hi.baidu.com/rebooo/item/12b500b130022bf263388e69假设A为主表(既含有某一主键的表),B为从表(即引用了A的主键作为外键)。则当删除A表时,如不特殊说明,则 drop table A 系统会出现如下错误警告的信息而不会允许执行。

ERROR at line 1:  ORA-02449: unique/primary keys in table referenced by foreign keys 

 

此时必须用,drop table A cascade constraints

之后,再查询约束:

SQL> select CONSTRAINT_NAME,TABLE_NAME from dba_constraints where owner = 'SYS' and TABLE_NAME = 'B' ;
no rows selected


利用Drop table cascade constraints可以删除从表的constraint,从而可实现drop table A。原属于B的foreign key constraint已经跟随着被删除掉了,但是,储存在table B中的记录不会被删除,也就是说Drop table cascade constraints 时不会影响到存储于objec里的row data。
 
posted @ 2014-11-08 14:02  程序员斯文  阅读(447)  评论(0编辑  收藏  举报