文档说
对于给定的表,不能有两个触发器具有相同的触发器操作时间和事件。
我使用 mysql 5.5.16。我创建了两个触发器。upd_check1
和sale_tri
。我确信我的两个触发器对INSERT
事件执行两个不同的表。但是为什么我在两个触发器中都得到这个错误。当我尝试导出数据库时(phpmyadmin 不显示错误,但 mysql 工作台、heidisql、查询浏览器显示错误)。
SQL 错误 (1235):此版本的 MySQL 尚不支持“一个表具有相同操作时间和事件的多个触发器”
这是我的upd_check1
触发器
--
-- Triggers `product_purchases`
--
DROP TRIGGER IF EXISTS `upd_check1`;
DELIMITER //
CREATE TRIGGER `upd_check1` AFTER INSERT ON `product_purchases`
FOR EACH ROW BEGIN
DECLARE X INTEGER;
SET X = (SELECT product_id FROM product_stock where product_id = NEW.product_id );
IF NEW.product_id =X THEN
UPDATE
product_stock AS S,
product_purchase_item AS I,
product_purchases AS P
SET
S.product_total_quantity=S.product_total_quantity+I.quantity
WHERE
S.product_id=I.product_id
AND
I.product_purchase_item_id=P.product_purchase_item_id
AND
P.product_purchase_id=NEW.product_purchase_id;
ELSE
INSERT INTO
product_stock (product_id,product_total_quantity)
SELECT
product_id, quantity
FROM
product_purchase_item
WHERE
product_purchase_item_id=NEW.product_purchase_item_id;
END IF;
END
//
DELIMITER ;
这是我的sale tri
触发器
--
-- Triggers `product_sales`
--
DROP TRIGGER IF EXISTS `sale_tri`;
DELIMITER //
CREATE TRIGGER `sale_tri` AFTER INSERT ON `product_sales`
FOR EACH ROW BEGIN
DECLARE X INTEGER;
SET X = (SELECT product_id FROM product_stock where product_id = NEW.product_id );
IF NEW.product_id =X THEN
update product_stock as s,
product_sale_item as i,
product_sales as p
SET s.product_total_quantity=s.product_total_quantity-i.quantity
WHERE s.product_id=i.product_id AND
i.product_sale_item_id=p.product_sales_item_id AND
p.product_sales_id=NEW.product_sales_id;
END IF;
END
//
DELIMITER ;