Sql 触发器不工作但不给出任何错误

Sql trigger doesn't work but doesn't give any error

我在 prestashop 上创建了一个触发器,以在产品缺货时更改产品的活动属性:

CREATE TRIGGER change_active AFTER UPDATE ON ps_stock_available
FOR EACH ROW
BEGIN
     UPDATE 
          ps_product_shop 
     SET 
          active=0 
     WHERE 
          id_product IN (SELECT id_product FROM ps_stock_available WHERE quantity=0);
END

它没有给我任何错误,所以它应该可以工作,但 active 属性永远不会改变,即使我将产品的数量设置为零也是如此。

编辑:经过多次尝试,我发现我的触发器在正确更新后没有被调用。这是我的代码,现在可以完美运行了。

 CREATE TRIGGER `change_active_after_update` AFTER UPDATE ON `ps_product`
 FOR EACH ROW
 BEGIN
      UPDATE 
           ps_product_shop 
      SET 
           active=0 
      WHERE 
          id_product IN(SELECT id_product FROM ps_stock_available WHERE quantity=0);
END

语句级触发器:

CREATE TRIGGER change_active ON ps_stock_available
FOR UPDATE
BEGIN
     UPDATE 
          ps_product_shop 
     SET 
          active=0
     FROM
        inserted
     WHERE 
          ps_product_shop.id_product = inserted.id_product and
          inserted.quantity=0;
END

行级触发器:

CREATE TRIGGER change_active BEFORE UPDATE ON ps_stock_available
FOR EACH ROW
BEGIN

IF(NEW.quantity = 0) THEN
     UPDATE 
          ps_product_shop 
     SET 
          active=0
     WHERE 
          ps_product_shop.id_product = NEW.id_product;
END IF;
END