Reputation: 2632
For some reason I'm running a blank on how to go about doing something like this.
I have a table that looks like this:
UserID | Name | DateAdded | LastUpated
--------------------------------------------------
1 | James Q | 1/1/2009 |
If I insert or update record the lastupdated field should be updated the sysdate. How would I go about doing something like this?
Upvotes: 8
Views: 9955
Reputation: 120997
CREATE OR REPLACE TRIGGER your_trigger_name
BEFORE INSERT OR UPDATE
ON your_table
FOR EACH ROW
DECLARE
BEGIN
:new.LastUpdated := sysdate;
END;
Try that. I did not have a oracle server at hand, but I hope I got the syntax right.
Upvotes: 13
Reputation:
create or replace trigger mytable_bi before insert on mytable for each row begin
:NEW.lastupdated := sysdate();
end;
create or replace trigger mytable_bu before update on mytable for each row begin
:NEW.lastupdated := sysdate();
end;
Upvotes: 0