Site search

Recent Posts

Meta

Categories

Posts

September 2008
M T W T F S S
« Aug   Dec »
1234567
891011121314
15161718192021
22232425262728
2930  

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 ;

Write a comment