MYSQL触发器问题-非常简单

发布于 2024-10-10 11:20:53 字数 251 浏览 2 评论 0原文

    DELIMITER $$
CREATE TRIGGER stock_empty AFTER UPDATE on products
    FOR EACH ROW
    DELETE FROM products WHERE stock <=0;
    END$$

我试图让我的产品表在每个 UPDATE 语句后进行自我检查,并删除库存数为 0 或负数的行。我可以做到这一点,但它不起作用。

感谢您的帮助

    DELIMITER $
CREATE TRIGGER stock_empty AFTER UPDATE on products
    FOR EACH ROW
    DELETE FROM products WHERE stock <=0;
    END$

I am trying to make my products table check itself after every UPDATE statement and delete rows that have 0 or negative stock counts. I could manage to get this far, but it is not working.

Thanks for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

给我一枪 2024-10-17 11:20:53

如果这么简单,你为什么不自己解决呢?

DELIMITER ||
CREATE TRIGGER stock_empty AFTER UPDATE on products
FOR EACH ROW BEGIN
DELETE FROM products WHERE stock <=0;
END ||

[编辑]

这就是正确的语法应该是什么样子,但是还有一件事:

存储的函数或触发器不能
修改已经存在的表
使用(用于阅读或写作)
调用函数的语句或
触发器。

来自: http://dev.mysql.com/doc /refman/5.5/en/stored-program-restrictions.html

If it's that easy, how come you didn't solve it yourself?

DELIMITER ||
CREATE TRIGGER stock_empty AFTER UPDATE on products
FOR EACH ROW BEGIN
DELETE FROM products WHERE stock <=0;
END ||

[edit]

That's how correct syntax should look like, however there's one more thing:

A stored function or trigger cannot
modify a table that is already being
used (for reading or writing) by the
statement that invoked the function or
trigger.

From: http://dev.mysql.com/doc/refman/5.5/en/stored-program-restrictions.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文