主外键约束的关闭和启用

昨天在进行数据库相应操作时,需要跟新表的主外键关联,通过实验,整理下一些sql语句:

/*查找所有引用某表主键为外键的表*/

其中PK_SRVMONITOR_SERVICE为该表的主键名

Sql代码

select c.constraint_name,

c.table_name,

c.constraint_type,

c.r_constraint_name

from user_constraints c

where c.r_constraint_name = 'PK_SRVMONITOR_SERVICE'

and c.constraint_type = 'R'

/*置主表主键约束为disable(级联)*/
alter table intf_t_classinfo disable primary key cascade;

/*置主表主键约束为enable*/
alter table intf_t_classinfo enable primary key;

/*为子表启用外键约束*/
alter table INTF_T_CLASSCOURSE enable novalidate constraint FK_INTF_T_C_RELATIABC_INTF_T_C;

posted @ 2013-07-31 09:11  萨普洛斯小纯洁  阅读(356)  评论(0编辑  收藏  举报