Run Trigger according to the value of a column

Asked

Viewed 45 times

0

I need this Rigger to run when there is an update in the table auction, but only when the column value auc_status is equal to 3.

That is, so the value of auc_status is changed to 3, he must run the Trigger.

I tried to do it that way:

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 otherwise? I use Mysql.

  • is not working? or you asked if there is another way to do?

  • It works, I just want to know if it’s the right way to do it so there’s no problems.

1 answer

0

I think it would be 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 ;
  • Perfect, what’s the difference of using the <> and <=>?

  • I don’t know, you assumed the "different" being <>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.