CREATE OR REPLACE TRIGGER DTULTATU_AGENTETERCECLI
BEFORE INSERT OR UPDATE OR DELETE
ON AGENTETERCECLI FOR EACH ROW
BEGIN
   IF INSERTING THEN
      :NEW.DTULTATU := SYSDATE;
   END IF;

   IF UPDATING THEN
      IF (NVL(:OLD.CDFILIAL,0)     <> NVL(:NEW.CDFILIAL,0))     OR
         (NVL(:OLD.CDCLIENTE,0)    <> NVL(:NEW.CDCLIENTE,0))    OR
         (NVL(:OLD.CDALMOXARIFE,0) <> NVL(:NEW.CDALMOXARIFE,0)) OR
         (NVL(:OLD.CDLOCALESTOQ,0) <> NVL(:NEW.CDLOCALESTOQ,0)) THEN
         :NEW.DTULTATU := SYSDATE;
      END IF;
   END IF;

   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('AGENTETERCECLI', '', 'CDFILIAL='||:OLD.CDFILIAL||';CDCLIENTE='||:OLD.CDCLIENTE||';', SYSDATE);
   END IF;
END;
/

ALTER TABLE AGENTETERCECLI MODIFY DTULTATU DEFAULT SYSDATE
/

-- VERSAO --
BEGIN ATUVEROBJ('DTULTATU_AGENTETERCECLI','5.85.xxx'); END;
/
