UPDATE_ON column in MySQL with trigger

I needed to update a column with the date and time whenever a record changed in my database. So here is the recipe for the trigger in MySQL 5.0.

DELIMITER $$

CREATE
    /*[DEFINER = { user | CURRENT_USER }]*/
    TRIGGER `my_database`.`UpdatedOn` BEFORE UPDATE
    ON `my_database`.`my_table`
    FOR EACH ROW BEGIN
set NEW.update_on = now();
    END$$

DELIMITER ;

Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>