这是我写的触发器。
DELIMITER //
create trigger after_insert_bid
after insert on Bid
for each row
when exists(
select *
from Item
where ItemID = new.ItemID)
begin
update Item set Item.currently = NEW.amount where Item.itemID = NEW.itemID;
end;//
DELIMITER ;
它有一个错误:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'when exists(
SELECT *
FROM Item
WHERE ItemID = new.ItemID
)
begin
UPDATE Item SE' at line 4
mysql> end;
我是mysql的新手,我知道这是一个简单的问题,但我真的不知道如何找到错误,谢谢!
mysql版本是5.1.73
答案 0 :(得分:0)
您无需检查项目表中是否存在itemid,只需直接更新项目表。如果Item表中不存在ItemID,则不会更新该表。
for each row
begin
update Item set Item.currently = NEW.amount where Item.itemID = NEW.itemID;
end