1

我正在尝试在数据库上创建触发器。我可以让它在 SQL fiddle 中正常工作,但是当我尝试在 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; 
4

2 回答 2

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; 
于 2015-02-18T12:35:13.703 回答
1

尝试设置分隔符:

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;
//
于 2019-05-10T16:10:13.153 回答