I supposed to make an sql trigger for update that will only activate when the affected rows are greater than 0. Yet, Even though the affected row is 0 (or the new record is identical to the old record) it still fires the trigger. I want to check the number of affected rows, before i execute the insert query below. Thanks in advance! Sorry for my grammar!
DELIMITER $$
DROP TRIGGER /*!50032 IF EXISTS */ `dbase`.`table_update_trigger`$$
CREATE
/*!50017 DEFINER = 'root'@'localhost' */
TRIGGER `table_update_trigger` AFTER UPDATE ON `table`
FOR EACH ROW BEGIN
IF (@@ROWCOUNT > 0) THEN
INSERT INTO
table_audit_trail
(column1,
column2,
column3,
column4,
column5,
column100)
VALUES
(old.column1,
old.column2,
old.column3,
old.column4,
old.column5,
old.column100);
END IF;
END;
There is no @@ROWCOUNT
in MySQL. You can read this post to find ount how to replace it.
But you dont need that. Your trigger is for each row
so it will fire for every updated row. (But that doesnt mean that your rows have changed. Just that they were updated by some statement.)