SQL触发器在MySQL中出现语法错误

时间:2016-05-17 05:28:15

标签: mysql database-trigger

DROP TRIGGER IF EXISTS demo_inc_when_viewstatus_one ;
DELIMITER $$

CREATE  TRIGGER demo_inc_when_viewstatus_one AFTER UPDATE ON `tbl_ffa_demo`
FOR EACH ROW BEGIN
UPDATE  `tbl_stats` SET open_demos=CASE WHEN NEW.demo_status=1  THEN 
 open_demos+1 , 
  total_demos=total_demos+1    WHERE  tbl_stats.area_id=NEW.territory  AND NEW.view_status=1
END $$
DELIMITER;

我收到的错误消息是:

  

1064 - 您的SQL语法出错;检查与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便在'附近使用。 total_demos = total_demos + 1 WHERE tbl_stats.area_id = NEW.territory AND NE'在第4行

1 个答案:

答案 0 :(得分:0)

您没有遵循case语句的语法:

case when <condition> then <true branch> else <false branch> end

所以,你应该有类似的东西:

...  SET open_demos=CASE WHEN NEW.demo_status=1
     THEN open_demos+1 ELSE open_demos=open_demos END, ...