我有一个问题。当我在inv_delivery表中插入新数据时,我试图从prod_runningtotal插入数据。因此,我使用TRIGGER自动执行此操作。这是我的触发代码:
CREATE DEFINER=`root`@`localhost` TRIGGER `A3A_SIS`.`inv_delivery_AFTER_INSERT` AFTER INSERT ON `inv_delivery` FOR EACH ROW
BEGIN
SET @prodname := (SELECT inv_prod_name FROM inv_delivery WHERE inv_id = (SELECT MAX(inv_id) FROM inv_delivery));
SET @prodcode := (SELECT prod_code FROM product_info WHERE prod_name = @prodname);
SET @quantity := (SELECT inv_quantity FROM inv_delivery WHERE inv_id = (SELECT MAX(inv_id) FROM inv_delivery));
INSERT INTO prod_runningtotal (product_code, running_total) VALUES (@prodcode, @quantity);
END
我没有收到任何错误。我可以成功地将数据插入到inv_delivery表中,但触发器不起作用。但是,如果我在mysql中单独运行触发器查询,它实际上可以工作。
那怎么可能?我该如何运作呢?预先谢谢你!