UPDATE_ON column in MySQL with trigger

By John C. Zastrow

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 ;