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
精彩评论