gpt4 book ai didi

mysql - 您的 SQL 语法有误...创建触发器时出现错误

转载 作者:行者123 更新时间:2023-11-30 21:46:16 24 4
gpt4 key购买 nike

我已经为我的数据库编写了触发器。

CREATE TRIGGER executor_type_check BEFORE INSERT ON executors 
FOR EACH ROW
BEGIN
IF NEW.points <> 100
SET NEW.points = 0;
END IF;
END

导入sql文件时出现如下错误

You have an error in your SQL syntax; 
check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SET NEW.points = 0' at line 5

我的 .sql 文件具有以下结构:

  1. 数据库创建
  2. 开始交易
  3. 创建表格
  4. 创建触发器
  5. promise

没有触发器不会显示错误。

最佳答案

根据您问题下方的评论

IF 语句后缺少 THEN。并且还需要添加DELIMITER

试试这个:

DELIMITER $$
CREATE TRIGGER executor_type_check BEFORE INSERT ON executors
FOR EACH ROW
BEGIN
IF NEW.points <> 100
THEN
SET NEW.points = 0;
END IF;
END;$$
DELIMITER ;

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

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