关于constraint 的disable和enable

建立主外键的constraint

create table emp1(emp_no number(2) constraint emp_emp_no_pk primary key,
ename varchar2(15),
salary number(8,2),
mgr_no number(2) constraint emp_mgr_fk references emp1);

 

查询状态

SQL> select constraint_name,constraint_type ,status from user_constraints where table_name='EMP1'
2 ;

CONSTRAINT_NAME C STATUS
------------------------------ - --------
EMP_EMP_NO_PK P ENABLED
EMP_MGR_FK R ENABLED

 

alter table emp1 disable constraint emp_emp_no_pk cascade;

 

SQL> select constraint_name,constraint_type ,status from user_constraints where table_name='EMP1';

CONSTRAINT_NAME C STATUS
------------------------------ - --------
EMP_EMP_NO_PK P DISABLED
EMP_MGR_FK R DISABLED

 

alter table emp1 enable constraint emp_emp_no_pk ;

 

SQL> select constraint_name,constraint_type ,status from user_constraints where table_name='EMP1';

CONSTRAINT_NAME C STATUS
------------------------------ - --------
EMP_EMP_NO_PK P ENABLED
EMP_MGR_FK R DISABLED

 

仍然需要手工enable外键constraint

alter table emp1 enable constraint emp_mgr_fk;

 

SQL> select constraint_name,constraint_type ,status from user_constraints where table_name='EMP1'
2 ;

CONSTRAINT_NAME C STATUS
------------------------------ - --------
EMP_EMP_NO_PK P ENABLED
EMP_MGR_FK R ENABLED

 

posted @ 2016-06-30 13:03  ericnie  阅读(3520)  评论(0编辑  收藏  举报