oracle中查詢、禁用、啟用、刪除表外鍵
來源:互聯網
上載者:User
oracle中查詢、禁用、啟用、刪除表外鍵
1.查詢所有表的外鍵的:select table_name, constraint_name from user_constraints where constraint_type = 'R'; 2.禁用所有外鍵約束, 使用下面的sql產生對應sql指令碼:select 'alter table ' || table_name || ' disable constraint ' || constraint_name || ';' from user_constraints where constraint_type = 'R';產生的sql類似下面的語句:alter table BERTH disable constraint BERTH_FK;alter table BOLLARD disable constraint BOLLARD_FK;alter table YARD_UNAVAIL_REGION disable constraint YARD_UNAVAIL_REGION_FK; 3.啟用所有外鍵約束, 使用下面的sql產生對應sql指令碼:select 'alter table ' || table_name || ' enable constraint ' || constraint_name || ';' from user_constraints where constraint_type = 'R';產生的sql類似下面的語句:alter table BERTH enable constraint BERTH_FK;alter table BOLLARD enable constraint BOLLARD_FK;alter table YARD_UNAVAIL_REGION enable constraint YARD_UNAVAIL_REGION_FK; 4.刪除所有外鍵約束, 使用下面的sql產生對應sql指令碼:select 'alter table ' || table_name || ' drop constraint ' || constraint_name || ';' from user_constraints where constraint_type = 'R';產生的sql類似下面的語句:alter table BERTH drop constraint BERTH_FK;alter table BOLLARD drop constraint BOLLARD_FK;alter table YARD_UNAVAIL_REGION drop constraint YARD_UNAVAIL_REGION_FK;