For implementing this issue you don't need to use trigger. That is because created
has logical meaning to be written once and for all. So you'll pass something like NOW()
when inserting your row.
Now, as for updated
, which has logical meaning of last change timestamp - then with defining timestamp field you can specify ON UPDATE CURRENT_TIMESTAMP clause:
CREATE TABLE t1 ( s TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, dt DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP );
-that's it. I.e. while in common case for update events you'll have to use triggers, this is the case, when MySQL provides built-in solution. To say more, this is the case when you're expected to use that - i.e. that is why it exist in MySQL.
Common answer to question 'when' is opinion based, but implementation of logical 'update date' is the general purpose.