2017-04-08 66 views
0

这是我写的触发器。mysql:触发器中的ERROR 1064(42000)

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的版本是73年5月1日

+0

您发现了错误。你是否检查了手册中的语法与指定的内容? – tadman

+0

我的版本是mysql 5.1.73。我试过在手册中发现它,但它没有工作.sorry –

+0

你不能在那里做一个'WHEN EXISTS',所以你需要一个不同的方法。看看有哪些* trigger_event *类型。 – tadman

回答

0

你并不需要检查项目表中是否存在的itemid只是直接更新项目表。如果ItemID在项目表中不存在,表格将不会更新。

for each row 
begin 
    update Item set Item.currently = NEW.amount where Item.itemID = NEW.itemID; 
end