gpt4 book ai didi

mysql - 创建触发器时出现 SQL 错误 #1064

转载 作者:行者123 更新时间:2023-11-29 13:14:17 25 4
gpt4 key购买 nike

我尝试在 MySQL 数据库中创建触发器,但总是收到错误:

#1064 - 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 DECLARE tmppl INT; SELECT MAX(PortListID) FROM pj_servers INTO t' at line 2

这是查询。我只是找不到错误。

CREATE TRIGGER init_new_server AFTER INSERT ON pj_servers
BEGIN
DECLARE tmppl INT;
SELECT MAX(PortListID) FROM pj_servers INTO tmppl;

INSERT INTO pj_servers (Registered, PortListID)
VALUES (Current_Timestamp, (tmppl+1))
WHERE pj_servers.ID = NEW.ID;

INSERT INTO pj_serverports (PortList, Port, isOpen, Script)
VALUES (tmppl+1, 80, TRUE, "say(\"Hallo\"");
END$$

最佳答案

根据MySQL Reference Manual :

CREATE
[DEFINER = { user | CURRENT_USER }]
TRIGGER trigger_name
trigger_time trigger_event
ON tbl_name FOR EACH ROW
trigger_body

trigger_time: { BEFORE | AFTER }

trigger_event: { INSERT | UPDATE | DELETE }

所以您可能在第一行中缺少FOR EACH ROW

关于mysql - 创建触发器时出现 SQL 错误 #1064,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21684237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com