MYSQL触发器查询

时间:2013-02-27 19:07:55

标签: mysql triggers

我正在尝试创建一个触发器来更新2个独立数据库之间的数量。此查询成功运行,但是当我在mysql中显示触发器时,它会显示一个空集。任何帮助将不胜感激。

delimiter $$ CREATE TRIGGER `quantity_to_clb` AFTER UPDATE ON product 
FOR EACH ROW BEGIN UPDATE cl_boutique.product AS clb 
LEFT JOIN cherrylane.product AS cl 
ON clb.model = cl.code SET clb.quantity = cl.available
 WHERE clb.model = cl.code
 END $$ 
delimiter ;

1 个答案:

答案 0 :(得分:2)

那是因为你的代码有两个synax错误:

delimiter $$ --delimiter statements need to be on separate lines
CREATE TRIGGER `quantity_to_clb` AFTER UPDATE ON product 
FOR EACH ROW BEGIN 
  UPDATE cl_boutique.product AS clb 
  LEFT JOIN cherrylane.product AS cl 
  ON clb.model = cl.code SET clb.quantity = cl.available
   WHERE clb.model = cl.code; -- ; was needed here
END $$ 
delimiter ;