开发者

MYSQL Trigger problem -Very Easy

    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 ev开发者_运维百科ery 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜