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?
While a procedure is explicitly executed by a user, application, or trigger, one or more triggers are implicitly fired (executed) by Oracle when a triggering INSERT, UPDATE, or DELETE statement is issued, no matter which user is connected or which application is being used.
The AFTER UPDATE trigger in MySQL is invoked automatically whenever an UPDATE event is fired on the table associated with the triggers. In this article, we are going to learn how to create an AFTER UPDATE trigger with its syntax and example.
A trigger fired by an INSERT statement has meaningful access to new column values only. Because the row is being created by the INSERT , the old values are null. A trigger fired by an UPDATE statement has access to both old and new column values for both BEFORE and AFTER row triggers.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With