Fire a trigger after the update of specific columns in MySQL Fire a trigger after the update of specific columns in MySQL mysql mysql

Fire a trigger after the update of specific columns in MySQL


You can't trigger on a particular column update in SQL. It is applied on a row.

You can put your condition for columm in your trigger with an IF statement, as below:

DELIMITER //CREATE TRIGGER myTrigger AFTER UPDATE ON myTableFOR EACH ROWBEGIN   IF !(NEW.column1 <=> OLD.column1) THEN      --type your statements here   END IF;END;//DELIMITER ;


You can't specify only to fire on specific column changes. But for a record change on a table you can do

delimiter |CREATE  TRIGGER  myTrigger AFTER UPDATE ON myTableFOR EACH ROWBEGIN   ...END|delimiter ;

In your trigger you can refer to old and new content of a column like this

if NEW.column1 <> OLD.column1 ...


As a solution, I did like that:

CREATE  TRIGGER  myTriggerAFTER UPDATE  ON myTableFOR EACH ROWBEGINIF NEW.myColumn1 <> OLD.myColumn1 || NEW.myColumn2 <> OLD.myColumn2then.....END IFEND