如何使用Sequel Pro创建触发器

时间:2013-08-15 10:54:21

标签: mysql

我正在尝试在db上创建触发器。我可以让它在SQL小提琴中正常工作,但当我尝试在Sequal Pro中创建触发器时,我只是得到一个错误..

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 8

这是SQL小提琴.. http://sqlfiddle.com/#!2/e849f/1

我使用的过程是在创建模式后在查询窗口中执行以下命令。

CREATE TRIGGER upd_selectoin 
BEFORE UPDATE ON main 
FOR EACH ROW 
BEGIN
   IF NEW.state = 3 THEN 
   UPDATE selection s JOIN main m 
      ON m.main_id = s.id
      SET s.allow = 1, last_update_timestamp = NOW()
   WHERE s.id = NEW.main_id; 
 END IF;
END; 

2 个答案:

答案 0 :(得分:5)

对于有同样问题的人:

Sequel Pro自己创造了周围的声明。 所以声明应该是这样的:

IF NEW.state = 3 THEN 
  UPDATE selection s JOIN main m 
    ON m.main_id = s.id
    SET s.allow = 1, last_update_timestamp = NOW()
  WHERE s.id = NEW.main_id;
END IF; 

答案 1 :(得分:0)

尝试设置定界符:

DELIMITER //
CREATE TRIGGER upd_selectoin 
BEFORE UPDATE ON main 
FOR EACH ROW 
BEGIN
   IF NEW.state = 3 THEN 
   UPDATE selection s JOIN main m 
      ON m.main_id = s.id
      SET s.allow = 1, last_update_timestamp = NOW()
   WHERE s.id = NEW.main_id; 
 END IF;
END;
//