简体   繁体   English

MySQL触发器#1064语法错误

[英]MySQL trigger #1064 syntax error

I have a database already in use on a server (MySQL Community Server 5.5.40-cll) & I'm trying to add a trigger to it but I keep getting the below error. 我已经在服务器(MySQL Community Server 5.5.40-cll)上使用了数据库,并且正在尝试向其添加触发器,但是我一直收到以下错误。

#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 '' at line 3 

I'm trying to set a trigger to make sure that end_date is not before start_date, here's what I'm currently using. 我正在尝试设置一个触发器,以确保end_date不在start_date之前,这是我当前正在使用的。

CREATE TRIGGER `Meets insert` BEFORE INSERT ON `meets`
  FOR EACH ROW 
    IF DATEDIFF(NEW.end_date, NEW.start_date) < 0 THEN
      signal sqlstate '45000' set message_text = 'start_date must be before end_date';
    END IF;

I've had a look in the MySQL documentation for 5.5 and it seems like everything I'm doing is supported by this version and I'm using it correctly. 我看过MySQL文档中的5.5版本,此版本似乎支持我正在做的所有事情,而且我正在正确使用它。

I'm sure the if statement is correct as I asked another similar question earlier here on Stack Overflow about a separate problem I was having which worked fine. 我确信if语句是正确的,因为我早些时候在Stack Overflow上问过另一个类似的问题,即我遇到的一个单独的问题很好用。 Although that was on a local development database where as this is on a server. 尽管那是在本地开发数据库上,因为它在服务器上。

If anyone can spot what I'm doing wrong or has an idea of what to check it will be appreciated. 如果有人能发现我在做什么错或对检查内容有任何想法,将不胜感激。

Thought I'd point out the server I'm making this change on isn't a production one. 以为我会指出要进行此更改的服务器不是生产服务器。

It appears to only be a lack of a DELIMTER wrapper. 似乎只是缺少DELIMTER包装器。 Try 尝试

delimiter $$
CREATE TRIGGER `Meets insert` BEFORE INSERT ON `meets`
  FOR EACH ROW 
    IF DATEDIFF(NEW.end_date, NEW.start_date) < 0 THEN
      signal sqlstate '45000' set message_text = 'start_date must be before end_date';
    END IF;
$$
delimiter ;

which gets past the Error 1064 通过错误1064

See the bottom of This Post for DELIMITER verbiage. 有关DELIMITER字词,请参见此帖子的底部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM