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;
It gives me the following error:
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
I'm a SQL Server guy by trade and can't put my finger on what the issue is.
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 ;
The semicolons in your trigger are screwing it up. You have to use the DELIMITER
keyword to change the delimiter that MySQL is using.
From http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html :
mysql> delimiter //
mysql> CREATE PROCEDURE simpleproc (OUT param1 INT)
-> BEGIN
-> SELECT COUNT(*) INTO param1 FROM t;
-> END//
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.