这个mysql创建触发器语句怎么了 [英] What's wrong with this mysql create trigger statement

查看:227
本文介绍了这个mysql创建触发器语句怎么了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CREATE TRIGGER google_inventory BEFORE UPDATE ON `cataloginventory_stock_item`
FOR EACH ROW 
BEGIN 
   update `catalog_product_entity_int` 
   set value=20 
   where attribute_id=552 
          and entity_id=NEW.product_id 
          and NEW.is_in_stock=0;
   update `catalog_product_entity_int` 
   set value=21 
   where attribute_id=552 
          and entity_id=NEW.product_id 
          and NEW.is_in_stock=1;
  END;

它给了我以下错误:

1064-您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本以使用正确的语法 在第4行的"附近

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 4

按行业来讲,我是一名SQL Server专家,不能专心解决问题所在.

I'm a SQL Server guy by trade and can't put my finger on what the issue is.

推荐答案

您需要更改定界符.没有它,分号将结束CREATE TRIGGER语句.

You need to change the delimiter. Without it, semicolon is ending CREATE TRIGGER statement.

delimiter |

CREATE TRIGGER google_inventory BEFORE UPDATE ON `cataloginventory_stock_item`
FOR EACH ROW 
BEGIN 
   update `catalog_product_entity_int` 
   set value=20 
   where attribute_id=552 
          and entity_id=NEW.product_id and NEW.is_in_stock=0;
   update `catalog_product_entity_int` 
   set value=21 
   where attribute_id=552 
          and entity_id=NEW.product_id and NEW.is_in_stock=1;
  END;
|

delimiter ;

这篇关于这个mysql创建触发器语句怎么了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆