两种方法人建议选择方法简单方便
方法:触发器解决(下面代码用修改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;