Execute trigger according to the value of a column

0

I need this trigger to be executed when there is an update in the auction table, but only when the value of the auc_status column is equal to 3 .

That is, as soon as the value of auc_status is changed to 3 , it must execute the trigger.

I tried to do this:

DELIMITER $$
CREATE TRIGGER update_bid
    AFTER UPDATE ON auction
    FOR EACH ROW    
BEGIN
IF (NEW.auc_status = '3') THEN
    /* Conteúdo da trigger, que seriam dois updates em outra tabela */
END IF;
END$$
DELIMITER ;

Is this correct or should I do it differently? I use MySQL.

    
asked by anonymous 20.03.2018 / 18:54

1 answer

0

I think it would look better

DELIMITER $$
CREATE TRIGGER update_bid
    AFTER UPDATE ON auction
    FOR EACH ROW    
BEGIN
IF ((OLD.auc_status <> NEW.auc_status) and (NEW.auc_status = '3')) THEN
    /* Conteúdo da trigger, que seriam dois updates em outra tabela */
END IF;
END$$
DELIMITER ;
    
21.03.2018 / 13:45