【问题标题】:mysql:ERROR 1064 (42000) in triggermysql:触发器中的错误1064(42000)
【发布时间】:2017-09-03 13:47:48
【问题描述】:

这是我写的触发器。

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

【问题讨论】:

  • 您发现了错误。您是否检查了语法与手册中指定的内容?
  • 我的版本是mysql 5.1.73。我试过在手册中找到它,但没有用。抱歉
  • 你不能在那里做WHEN EXISTS,所以你需要一种不同的方法。看看有哪些 trigger_event 类型。

标签: mysql error-handling triggers


【解决方案1】:

您不需要检查itemid是否存在于item table中,直接更新item table即可。如果 Item 表中不存在 ItemID,则不会更新该表。

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

【讨论】:

    猜你喜欢
    • 2011-12-06
    • 1970-01-01
    • 2018-03-05
    • 1970-01-01
    • 1970-01-01
    • 2015-11-09
    • 2012-02-20
    • 2016-02-16
    • 1970-01-01
    相关资源
    最近更新 更多