0

I trying to after update table, update new update_time. Whats my wrong?

DELIMITER $$
CREATE TRIGGER after_update AFTER UPDATE ON urunler
    FOR EACH ROW 
        BEGIN
            IF NEW.adi != OLD.adi THEN
                UPDATE urunler SET update_time=now();
            END IF;
        END$$
DELIMITER ;

getting error

#1442 - Can't update table 'urunler' in stored function/trigger because it is already used by statement which invoked this stored function/trigger

SOLVED WITH "BEFORE" not AFTER...

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
DCYılmaz
  • 95
  • 7
  • Does this answer your question? [#1442 - Can't update table '\*' in stored function/trigger because it is already used by statement which invoked this stored function/trigger](https://stackoverflow.com/questions/41537750/1442-cant-update-table-in-stored-function-trigger-because-it-is-already) – Alberto Moro Feb 18 '20 at 13:11

1 Answers1

0

To apply a DML operation on the same table may raise mutating table error.

Rather, replace UPDATE urunler SET update_time=now(); with SET new.update_time = now();

where [old/new].update_time expression represents a column within that table.

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55