set serveroutput on
ALTER TABLE dept ADD CONSTRAINT dept_pk PRIMARY KEY(deptno);
ALTER TABLE emp ADD CONSTRAINT emp_dept_fk FOREIGN KEY(deptno) REFERENCES dept(deptno);
ALTER TABLE emp ADD CONSTRAINT emp_ename_uk UNIQUE(ename);

CREATE OR REPLACE TRIGGER Zly1
BEFORE UPDATE
ON dept
BEGIN
  DBMS_OUTPUT.Put_Line('zly1');
  UPDATE emp SET deptno = deptno WHERE ename = 'KING';
END;
/

update dept set dname=dname;

DROP TRIGGER zly1;

------------------

CREATE OR REPLACE TRIGGER Zly2
AFTER UPDATE
ON dept
BEGIN
  DBMS_OUTPUT.Put_Line('zly2');
  UPDATE emp SET ename = ename WHERE ename = 'KING';
END;
/

update dept set dname=dname;

DROP TRIGGER zly2;

------------------

CREATE OR REPLACE TRIGGER dobry1
BEFORE UPDATE
ON dept
BEGIN
  DBMS_OUTPUT.Put_Line('dobry1');
  UPDATE emp SET sal = sal;
END;
/

update dept set dname=dname;

DROP TRIGGER dobry1;

------------------

CREATE OR REPLACE TRIGGER Zly3
BEFORE UPDATE
ON dept
FOR EACH ROW
BEGIN
  DBMS_OUTPUT.Put_Line('zly3');
  UPDATE emp SET deptno = deptno WHERE deptno = :old.deptno;
END;
/

update dept set dname=dname;

DROP TRIGGER zly3;

------------------

CREATE OR REPLACE TRIGGER Zly4
AFTER UPDATE
ON dept
FOR EACH ROW
BEGIN
  DBMS_OUTPUT.Put_Line('zly4');
  UPDATE emp SET ename = ename WHERE deptno = :old.deptno;
END;
/

update dept set dname=dname;

DROP TRIGGER zly4;

------------------

CREATE OR REPLACE TRIGGER dobry2
BEFORE UPDATE
ON dept
FOR EACH ROW
BEGIN
  DBMS_OUTPUT.Put_Line('dobry2');
  UPDATE emp SET sal = sal WHERE deptno = :old.deptno;
END;
/

update dept set dname=dname;

DROP TRIGGER dobry2;

ALTER TABLE emp DROP CONSTRAINT emp_dept_fk;
ALTER TABLE emp DROP CONSTRAINT emp_ename_uk;
ALTER TABLE dept DROP CONSTRAINT dept_pk;
