zoukankan      html  css  js  c++  java
  • 级联删除

    两种方法人建议选择方法简单方便

    方法:触发器解决(下面代码用修改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;

  • 相关阅读:
    MYSQL ALTER
    初入园子
    java常用基础(一)
    C语言类型转换
    C++用EGE简单实现别踩白块游戏
    CPP常用库函数以及STL
    至我的新博客
    工厂模式
    pl/sql developer 编码格式设置
    单例模式
  • 原文地址:https://www.cnblogs.com/wangcq/p/3615099.html
Copyright © 2011-2022 走看看