Skip to content Skip to sidebar Skip to footer

Using Concat With Mysql Triggers (error At ,)

I am trying to create a trigger to write logs when rows in x table have been edited. This is the current query.. CREATE TRIGGER users_update_trigger AFTER UPDATE ON users FOR EACH

Solution 1:

UPDATED:

  1. It looks like you didn't changed DELIMITER.
  2. You most likely meant CURRENT_TIMESTAMP instead of nonexistent CURTIMESTAMP()

That being said a syntactically correct version of your trigger might look like

DELIMITER $$
CREATETRIGGER users_update_trigger
AFTER UPDATEON users 
FOREACHROWBEGININSERTINTO users_backlog (user_id, description, datetime) VALUES 
  (NEW.user_id, CONCAT('modified from ', OLD.hourly, ' to ', NEW.hourly), CURRENT_TIMESTAMP);
END$$
DELIMITER ;

or (because you have the only one statement in your trigger you can omit BEGIN ... END block and DELIMITER) simply

CREATETRIGGER users_update_trigger
AFTER UPDATEON users 
FOREACHROWINSERTINTO users_backlog (user_id, description, datetime) VALUES 
  (NEW.user_id, CONCAT('modified from ', OLD.hourly, ' to ', NEW.hourly), NOW());

Here is SQLFiddle demo

Solution 2:

You didn't set the DELIMITER to something different than ; before running your definition.

Post a Comment for "Using Concat With Mysql Triggers (error At ,)"