gpt4 book ai didi

mysql - 为什么说这个触发器包含sql语法错误?

转载 作者:行者123 更新时间:2023-11-29 21:38:25 25 4
gpt4 key购买 nike

我在mysqlworkbench中编写了一个触发器,该触发器应该在将新行添加到订单表后更新产品库存(我的代码是荷兰语,所以这就是我解释这一点的原因)但是当我尝试时它不起作用应用它 mysqlworkbench 说它的 sql 代码包含错误。

这是触发器:

CREATE DEFINER = CURRENT_USER TRIGGER `winkel`.`bestelregel_AFTER_INSERT` AFTER INSERT ON `bestelregel` FOR EACH ROW
BEGIN
if Product.productnr = NEW.productnr
then
Update Product
Set Hoeveelheid = (Hoeveelheid - NEW.aantal)
Where productnr = NEW.productnr;

end if;
END

最佳答案

if 语句中的 Product 是什么?也就是说,毫无疑问,会生成语法错误,因为它无法识别。

我认为你想让 body 变得简单:

    Update Product p.
Set Hoeveelheid = (Hoeveelheid - NEW.aantal)
Where p.productnr = NEW.productnr;

if 无关紧要。

我希望完整版本看起来像这样:

DELIMITER $$

CREATE DEFINER = CURRENT_USER TRIGGER `winkel`.`bestelregel_AFTER_INSERT`
AFTER INSERT ON `bestelregel` FOR EACH ROW
BEGIN
UPDATE Product p
SET Hoeveelheid = (Hoeveelheid - NEW.aantal)
WHERE p.productnr = NEW.productnr;
END $$

DELIMITER ;

关于mysql - 为什么说这个触发器包含sql语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34729687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com