您的位置:首页 > 数据库 > Oracle

oracle 删除外键约束 禁用约束 启用约束

2016-02-16 11:05 686 查看

oracle 删除外键约束 禁用约束 启用约束

执行以下sql生成的语句即可

删除所有外键约束

Sql代码

select 'alter table '||table_name||' drop constraint '||constraint_name||';' from user_constraints where constraint_type='R'


禁用所有外键约束

Sql代码

select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints where constraint_type='R'


启用所有外键约束

Sql代码

select 'alter table '||table_name||' enable constraint '||constraint_name||';' from user_constraints where constraint_type='R'


主表 MANTIS_USER 与 子表 MANTIS_USER_ORGAN

-- 创建外键(默认选项)

ALTER TABLE MANTIS_USER_ORGAN ADD CONSTRAINT fk_MANTIS_USER_ORGAN_ORG  FOREIGN KEY (org_id)  REFERENCES MANTIS_USER (ID);


--删除外键约束

ALTER TABLE MANTIS_USER_ORGAN DROP CONSTRAINT FK_MANTIS_USER_ORGAN_ORG;


参考文章:

http://qindingsky.blog.163.com/blog/static/312233620109292562735/
http://blog.csdn.net/laodao1/article/details/6446953
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: