【发布时间】:2022-11-18 03:22:27
【问题描述】:
我正在尝试创建一个触发器,其中一旦将一行插入到 Vote 表中,Monitor 表中的一个字段就会递增 1——递增的行是最近的值“monitor_id”的行插入的行与 Monitor 表中的字段“staff_id”相匹配。
这是我的代码,我在 Jupyter Notebook 中运行它,并连接到我本地机器上的 MySQL 数据库:
CREATE TRIGGER update_votes_presided_over
AFTER INSERT ON Vote
BEGIN
UPDATE Monitor
SET num_votes_presided = num_votes_presided + 1
WHERE new.monitor_id == Monitor.staff_id;
END;
但我收到此错误:
* mysql+mysqlconnector://root:***@localhost/elections
sqlite:///hw2.sqlite
(mysql.connector.errors.ProgrammingError) 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 'BEGIN
UPDATE Monitor
SET num_votes_presided = num_votes_presided + 1
' at line 3
[SQL: CREATE TRIGGER update_votes_presided_over
AFTER INSERT ON Vote
BEGIN
UPDATE Monitor
SET num_votes_presided = num_votes_presided + 1
WHERE new.monitor_id == Monitor.staff_id;
END;]
(Background on this error at: https://sqlalche.me/e/14/f405)
有人知道我做错了什么吗?
谢谢!
【问题讨论】:
标签: mysql sql jupyter-notebook triggers