之前做測試,A表中有主鍵是作為B表和C表的外鍵的,現在想要刪除ABC三個表,發現單純使用DROP是無法刪除的
會報錯( 無法禁用約束條件 (XXXXXXXXX) - 存在相關性)這時候就需要我們把外鍵約束全部干掉。
在網上找到了非常實用的demo:
第一步查出所有的外鍵
select 'alter table '||table_name||' enable constraint '||constraint_name||';' from user_constraints where constraint_type='R';select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints where constraint_type='R';
直接把這句話copy過去就可以查到外鍵
再執行alter table table_name disable constraint xxx;就可以將外鍵禁用,然后執行DROP命令就可以刪除了。