junior junior - 5 months ago 17
MySQL Question

fire a trigger after the update of specific columns in mysql

In MySQL, I want to fire a trigger after the update of specific columns,
in Oracle and DB2, I know how to do:

CREATE TRIGGER myTrigger
AFTER UPDATE of myColumn1,myColumn2 ... ON myTable
FOR EACH ROW
BEGIN
....
END


How to do that with MySQL?

Answer

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, as below:

CREATE  TRIGGER  myTrigger AFTER UPDATE ON myTable
 FOR EACH ROW
BEGIN
if NEW.column1 <> OLD.column1
begin 
--your statements here
end
END