mysql - 这个mysql create trigger语句有什么问题

标签 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 - 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 专业人士,无法确定问题所在。

最佳答案

您需要更改分隔符。没有它,分号将结束 CREATE TRIGGER 语句。

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 - 这个mysql create trigger语句有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10049401/

相关文章:

java - 根据表单值从数据库中获取数据

php - 从 HTML 表单向 MySQL 数据库插入多行

php - Laravel Eloquent -- 表中的多条记录插入(具有唯一约束的列)

javascript - 当在 AJAX、Jquery 中使用 GET 更新数据库时,如何反射(reflect)表上的更新

mysql - Npm Mysql 连接错误

php - mysqli_fetch_array($link, $query) 直接查询数据库时未输出预期结果

php - 为什么我收到此错误,一切看起来都正确 : "Undefined index"?

mysql - 如何撤销一个架构(crm)和用户(cus)中一张表的更新授权

php - Mysql插入查询,未知错误

php - 我可以加入表并在同一个查询中使用 AVG