Reputation: 375
I would like to fire an UPDATE trigger only if a certain fields has been modified. Is it possible to do with a if statement; execute a particular query.
Exemple (Not working as shown):
DROP TRIGGER IF EXISTS `catch_mytable_update`//
CREATE TRIGGER `catch_mytable_update` AFTER UPDATE ON `mytable`
FOR EACH ROW BEGIN
IF (old.name != new.name) THEN
DELETE FROM trigger WHERE tablename='mytable' AND rowid = new.id;
INSERT INTO trigger (tablename, rowid, cmd, cmduser, time) VALUES('mytable', new.id, 'UPDATE', CURRENT_USER(), NOW());
ENDIF//
END//
Delimiter: //
Upvotes: 0
Views: 571
Reputation: 46
Try changing:
IF (name.old != name.new) THEN
to:
IF old.name != new.name THEN
Upvotes: 1