兩種方法人建議選擇方法簡單方便
方法:觸發器解決(下面代碼用修改copy直接用)
create or replace trigger delete_dept
before delete on DEPT
for each row
begin
delete from EMP where DEPT_NO = :old.DEPT_NO;
delete from POS where DEPT_NO = :old.DEPT_NO;
end;
/
方法二:修改外鍵設置達級聯刪除目具體實現下:
a)先查詢出EMP表和POS表 外鍵名稱(知道 外鍵名步省略)
select CONSTRAINT_NAME,TABLE_NAME from user_constraints where CONSTRAINT_TYPE ='R' and TABLE_NAME in('EMP','POS');
b)刪除EMP表和POS表上外鍵 重新建立允許級聯刪除外鍵模式
alter table EMP drop constraint 外鍵名;
alter table POS drop constraint 外鍵名;
alter table EMP add constraint 外鍵名 foreign key(DEPT_NO) references DEPT(DEPT_NO) on delete cascade;
alter table POS add constraint 外鍵名 foreign key(DEPT_NO) references DEPT(DEPT_NO) on delete cascade;