我有两张桌子,
QuerySetManager
在RawFeed , SellerList.
中插入新行时,如果RawFeed
中不存在相应的SellerList
,我需要在SellerID
中插入一行,
否则,我需要在SellerList
表中为该SellerList
增加两个列值。
这是我的触发代码 -
SellerID
我收到此错误 -
CREATE TRIGGER `SellerListUpdate` AFTER INSERT ON `RawFeed`
FOR EACH ROW
BEGIN
--CHECK SELLER ID EXISTS OR NOT.
DECLARE SELLEREXISTS INT;
SELECT COUNT(*) INTO SELLEREXISTS FROM SellerList WHERE SellerList.SellerID=NEW.seller_id;
IF SELLEREXISTS=0 THEN
--INSERT ROW
INSERT INTO SellerList(`SellerID`, `Total`, `Active`) VALUES(NEW.seller_id, 1, 1);
ELSE
--UPDATE ROW
UPDATE SellerList SET Total=Total+1, Active=Active+1 WHERE SellerList.SellerID=NEW.seller_id;
END IF;
END
答案 0 :(得分:1)
尝试更改分隔符
DELIMITER $$
CREATE TRIGGER `SellerListUpdate` AFTER INSERT ON `RawFeed`
FOR EACH ROW
BEGIN
--CHECK SELLER ID EXISTS OR NOT.
DECLARE SELLEREXISTS INT;
SELECT COUNT(*) INTO SELLEREXISTS FROM SellerList WHERE SellerList.SellerID=NEW.seller_id;
IF SELLEREXISTS=0 THEN
--INSERT ROW
INSERT INTO SellerList(`SellerID`, `Total`, `Active`) VALUES(NEW.seller_id, 1, 1);
ELSE
--UPDATE ROW
UPDATE SellerList SET Total=Total+1, Active=Active+1 WHERE SellerList.SellerID=NEW.seller_id;
END IF;
END
$$
DELIMITER ;