我在插入触发器后写了下面的内容,它没有给我任何错误。但是每当我尝试将数据插入sept18.test时,我都会遇到错误
错误代码:1442。无法更新存储的函数/触发器中的表“ test” 因为调用该存储的语句已使用它 功能/触发。 0.000秒
有人可以帮助我解决此错误。谢谢你的配合。
-- SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME = 'TR_ORDERS_INS'
DROP TRIGGER IF EXISTS TR_ORDERS_INS;
DELIMITER $$
CREATE TRIGGER TR_ORDERS_INS
AFTER INSERT ON sept18.test for each row
BEGIN
DECLARE MAX_DATE1 DATETIME;
IF EXISTS
(
select 1 from ept18.test O
where O.STOREID = NEW.STOREID
AND O.ITEMID = NEW.ITEMID
AND O.ORDERDATE = NEW.ORDERDATE
)
THEN
SET MAX_DATE1 = (SELECT max(DateTimeStamp)
from sept18.test
where itemid = NEW.itemid
and storeid = NEW.storeid
and OrderDate = NEW.orderdate);
INSERT INTO sep18kentest.orders_history
(ORDERID,STOREID,ITEMID,ORDERDATE,QUANTITY,BONUSBUCK,FLATBONUSBUCK,PRICE,STOREPRICE,PRICEOVERRIDE,
PRICEOVERRIDEFLAG,DIRECTSHIPFLAG,FREEITEMFLAG,SRP,DATETIMESTAMP,RECORDNUMBER)
SELECT ORDERID,STOREID,ITEMID,ORDERDATE,QUANTITY,BONUSBUCK,FLATBONUSBUCK,PRICE,STOREPRICE,PRICEOVERRIDE,
PRICEOVERRIDEFLAG,DIRECTSHIPFLAG,FREEITEMFLAG,SRP,DATETIMESTAMP,RECORDNUMBER
FROM sept18.test OD
WHERE OD.storeid = NEW.storeid
and OD.itemid = NEW.itemid
and OD.orderdate = NEW.orderdate
and OD.DateTimeStamp < MAX_DATE1;
DELETE FROM sept18.test
WHERE storeid = NEW.storeid
and itemid = NEW.itemid
and orderdate = NEW.orderdate
and DateTimeStamp < MAX_DATE1;
END IF;
END$$