1. 程式人生 > >oracle 外來鍵操作

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;

覺得文章實用,請在右上方點個贊