2012-04-06 7 views
2
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; 

Es mir folgende Fehler gibt:Was ist mit diesem mysql falsch erstellen Trigger Anweisung

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

ich einen SQL Server Typen durch Handel bin und kann meinen Finger nicht anziehen, was das Problem ist.

+0

was NEW.product_id und NEW.is_in_stock? ist es von einer anderen Tabelle, wenn ja, dann müssen Sie sich daran anschließen – Taryn

+0

Neu ist die Triggersyntax, die sich auf die Änderungen bezieht, die in der Tabelle gemäß diesem Dokument gemacht werden http://dev.mysql.com/doc/refman /5.0/de/create-trigger.html – RThomas

Antwort

5

Sie müssen das Trennzeichen ändern. Ohne es endet Semikolon CREATE TRIGGER-Anweisung.

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 ; 
+0

froh, dass ich gefragt habe ... Ich hätte das nie auf meine eigene begrenzte mysql Erfahrung gebracht. Vielen Dank. – RThomas

+0

Ich bin froh, dass ich helfen konnte :) –

3

Die Semikolons in Ihrem Trigger verschrauben es. Sie müssen das Schlüsselwort DELIMITER verwenden, um das Trennzeichen zu ändern, das MySQL verwendet.

Von 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 ;