Thursday, November 7, 2013

017. JAVADB-DERBY: CREATE TRIGGER

 Assume: We have read and understood JAVADB-DERBY: CREATE PROCEDURE


  • Create trigger after insert:
    CREATE TRIGGER APP.TRG_AFTERINS
    AFTER INSERT ON MYSCHEMA.MYOTHERTABLE
    REFERENCING NEW AS NEW
    FOR EACH ROW
    CALL APP.APROCFORTRIGGER_AFTERINS(CAST (NEW.OTHERFIELD1  AS VARCHAR(20),
         CAST (NEW.OTHERFIELD2  AS VARCHAR(20));

  • Create trigger after update:
    CREATE TRIGGER APP.TRG_AFTERUPD
    AFTER UPDATE ON MYSCHEMA.MYOTHERTABLE
    REFERENCING OLD AS OLD NEW AS NEW
    FOR EACH ROW
    CALL APP.APROCFORTRIGGER_AFTERINS(CAST (NEW.OTHERFIELD1  AS VARCHAR(20),
         CAST (OLD.OTHERFIELD2  AS VARCHAR(20));

  • Create trigger after delete:
    CREATE TRIGGER APP.TRG_AFTERDEL
    AFTER DELETE ON MYSCHEMA.MYTABLE
    REFERENCING OLD AS OLD
    FOR EACH ROW
    DELETE FROM MYSCHEMA.MYOTHERTABLE WHERE OTHERFIELD1=OLD.MYFIELD1 AND OTHERFIELD2=OLD.MYFIELD2;


Do you really want to try?