I need to fill in the Mysql table field. Directly for technical reasons, it does not work, so I use a temporary field and a trigger. It should work like this: if the temporary field is not empty, then you need to take the value of the temporary field and set it to the desired one, and set the temporary field to NULL . If I do this: I create a BEFORE UPDATE trigger

 IF NEW.field_tmp IS NOT null THEN SET NEW.field_1 = NEW.field_tmp; SET NEW.field_tmp = null ; END IF 

Then in this case both fields are set to NULL . The code below works well, but does not reset the temporary field.

 IF NEW.field_tmp IS NOT null THEN SET NEW.field_1 = NEW.field_tmp; END IF 

Is it possible to solve this problem in one trigger, or you need to add a second AFTER UPDATE trigger:

 IF NEW.field_tmp IS NOT null THEN SET NEW.field_tmp = null ; END IF 

    1 answer 1

    You can use the @temp temporary variable to store the intermediate value.

     DELIMITER // CREATE TRIGGER tbl_update BEFORE UPDATE ON tbl FOR EACH ROW IF NEW.field_tmp IS NOT NULL THEN SET @temp := NEW.field_tmp; SET NEW.field_1 = @temp; SET NEW.field_tmp = NULL; END IF//