oracle 外键操作

– 创建

alter table 表名 add constraint 外键名 foreign key(从表外键字段) references foreign_main(主表外键字段);

– 查询外键

select table_name, constraint_name from user_constraints where constraint_type = 'R';

– 禁用外键

select 'alter table SYS_MENU disable constraint FK_SYS_MENU_REFERENCE_SYS_RESO;' from user_constraints where constraint_type = 'R';

alter table SYS_MENU disable constraint FK_SYS_MENU_REFERENCE_SYS_RESO;

– 启用外键

select 'alter table SYS_MENU enable constraint FK_SYS_MENU_REFERENCE_SYS_RESO;' from user_constraints where constraint_type = 'R';  

alter table SYS_MENU enable constraint FK_SYS_MENU_REFERENCE_SYS_RESO;

– 删除外键

select 'alter table SYS_MENU drop constraint FK_SYS_MENU_REFERENCE_SYS_RESO;' from user_constraints where constraint_type = 'R'; 

alter table SYS_MENU drop constraint FK_SYS_MENU_REFERENCE_SYS_RESO;
 

觉得文章实用,请在右上方点个赞

 

你可能感兴趣的:(oracle)