vishnudas
vishnudas

Reputation: 53

Update the same table if INSERTED or UPDATED

I have a table with 4 fields (ID is auto generated)

CREATE TABLE MASTER_ARCH ( 
  ID NUMBER(5),
  NAME VARCHAR2(50 CHAR),
  AGE NUMBER(3),
  LAST_MOD_DT DATE 
);

My requirement is, if the table is getting inserted by new rows or updating existing rows then value for the column LAST_MOD_DT should be SYSDATE.

Upvotes: 0

Views: 60

Answers (2)

VBoka
VBoka

Reputation: 9083

This should do the job:

CREATE OR REPLACE TRIGGER TRIGGER1 
BEFORE INSERT OR UPDATE ON MASTER_ARCH 
FOR EACH ROW
BEGIN
  :new.LAST_MOD_DT := sysdate;
END;

Upvotes: 2

vishnudas
vishnudas

Reputation: 53

I had to add,

create or replace TRIGGER MASTER_ARCH_DT 
BEFORE INSERT OR UPDATE ON MASTER_ARCH
FOR EACH ROW
BEGIN
  :new.LAST_MOD_DT := sysdate;
END;

Upvotes: 0

Related Questions