mysql Trigger if not update

Asked

Viewed 308 times

0

I have a question when creating a Trigger, I need it to be executed only if the field has not been updated: integraProduct, if any other field is updated it should be executed.

DELIMITER $$
CREATE
    TRIGGER `cadastro`.`trgProdutos` AFTER UPDATE
    ON `cadastro`.Produtos
   FOR EACH ROW BEGIN
     IF NOT UPDATE(integraProduto) THEN
    SET NEW.integraProduto=1;
     END IF;
    END$$
DELIMITER ;

error: Error Code: 1064 You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near 'UPDATE(integraProduct) THEN SET NEW.integraProduct=1; END IF;

  • there is no html, because the problem is in mysql Trigger, my question is how to create a Trigger with this condition: IF NOT UPDATE(integraProduct)

1 answer

2


Solved:

DELIMITER $

CREATE TRIGGER `cadastro`.`trgProdutos` BEFORE UPDATE ON `cadastro`.Produtos FOR EACH ROW 

BEGIN
   IF (new.integraProduto = old.integraProduto) THEN
      SET NEW.integraProduto=1;
   END IF;
END$

DELIMITER ;

Browser other questions tagged

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