MySQL Forums
Forum List  »  Newbie

Re: TRIGGER
Posted by: Peter Brawley
Date: March 15, 2015 10:49PM

Given table Log ( UserName varchar(20), Action varchar(20), Date datetime), your MySQL update trigger would look like this ...

CREATE TRIGGER Watch AFTER UPDATE ON ORDERS AS
INSERT INTO Log(new.UserName, Action, Date) VALUES (USER(), 'Update', CURDATE());

As Barry suggests, see the MySQL manual page for Triggers.

But a log like that isn't an efficient audit trail---you're writing each column value twice! Mmore efficient: lose the orders table, emulate it with a View, and implement transaction state logic in insert/update/delete code for orders. see "Point-in-time architecture" at http://www.artfulsoftware.com/infotree/mysqltips.php .

Options: ReplyQuote


Subject
Written By
Posted
P L
March 15, 2015 03:09PM
March 15, 2015 05:09PM
Re: TRIGGER
March 15, 2015 10:49PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.