CASCADE CONSTRAINTS
Specify CASCADE CONSTRAINTS to drop all referential integrity constraints that refer to primary and unique keys in the dropped table. If you omit this clause, and such referential integrity constraints exist, then the database returns an error and does not drop the table.
SUNDOG315>create table t_p (id integer,text varchar2(20));
表已创建。
SUNDOG315>alter table t_p add constraints t_p_pk primary key(id);
表已更改。
SUNDOG315>create table t_c(id integer,child_text varchar2(20));
表已创建。
SUNDOG315>alter table t_c add constraints t_c_fk foreign key(id) references t_p(
id);
表已更改。
SUNDOG315>select constraint_name,constraint_type from user_constraints;
CONSTRAINT_NAME C
------------------------------ -
T_C_FK R
T_P_PK P
SUNDOG315>drop table t_p;
drop table t_p
*
第 1 行出现错误:
ORA-02449: 表中的唯一/主键被外键引用
SUNDOG315>drop table t_p cascade constraints;
表已删除。
SUNDOG315>desc t_p
ERROR:
ORA-04043: 对象 t_p 不存在
SUNDOG315>desc t_c
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
ID NUMBER(38)
CHILD_TEXT VARCHAR2(20)
SUNDOG315>select constraint_name,constraint_type from user_constraints;
未选定行