MySQL INSERT INTO ON DUPLICATE KEY UPDATE , regarding update triggers

This is to share some insight on the subject of mysql triggers in connection with INSERT INTO ON DUPLICATE KEY UPDATE statement.

When you execute an SQL UPDATE query, the update triggers are fired regardless of whether you changed a value or not in a specific row.
e.g.

UPDATE myTable SET myColumn='test' WHERE id=100;

The above query will fire the update trigger (before or after) even if ‘myColumn’ already has the value ‘test’ for row with id=100

This is not the case with INSERT INTO ON DUPLICATE KEY UPDATE query.

e.g.

INSERT INTO myTable (`id`, `myColumn`) VALUES (100, 'test') ON DUPLICATE KEY UPDATE myColumn='test';

The above query will not fire any UPDATE trigger if there is already a row with id=100 and ‘myColumn’ already has value ‘test’ !!!

Cheers.