pl/sql常用刪除觸發器

 

--題目:編寫一個數據庫觸發器,當任何時候某個部門的從dept表中刪除的時,該觸發器將從emp表中刪除該部門的所有雇員。   

CREATE OR REPLACE TRIGGER TRI_G1

 BEFORE DELETE ON DEPT

 FOR EACH ROW

 BEGIN

 DELETE FROM emp where DEPORTNO=:OLD.DEPT_NO;

 END;

 

 select * from emp

 select * froM DEPT

 

 INSERT INTO DEPT(DEPT_NO,DEPT_NAME) VALUES(3,'C')

 BEGIN

   INSERT INTO EMP(EMPNO,ENAME,SALARY,COMM,DEPORTNO) VALUES(7986,'gangge',2001,35000,3);

   INSERT INTO EMP(EMPNO,ENAME,SALARY,COMM,DEPORTNO) VALUES(7895,'WA',2100,25000,3);

 END;

 DELETE FROM DEPT WHERE DEPT_NO=3

你可能感兴趣的:(pl/sql)