-1

I have created this trigger in HeidiSQL IDE for mysql trough IDE´s helper and it worked pretty good. If I copy the create code generated by the IDE and try to run it on phpmyadmin I get a SQL syntax error that I just can´t figure how to fix it. Can anyone help me?

CREATE TRIGGER `teste` AFTER UPDATE ON `ilmug_virtuemart_products` FOR EACH ROW BEGIN
   IF (NEW.origem_sync <> 0) THEN 
      INSERT INTO sincronizar (dataHora,
                               tipoMovimento,
                               entidade,
                               id,
                               version,
                               STATUS) 
                       VALUES (CURRENT_TIMESTAMP(),
                  'update',
                  'virtuemart_products',
                   NEW.virtuemart_product_id,
                   NEW.version,
                  'pendente');
   END IF;
END;
Daniel
  • 273
  • 4
  • 18

2 Answers2

0

You have a BEGIN statement...but the END is missing


Since you have edited your question, I tested it: http://sqlfiddle.com/#!2/0ebbf
According to sqlfiddle, there is no syntax error...

Sylvain Leroux
  • 50,096
  • 7
  • 103
  • 125
  • This is not the problem, i´ve tried many different types of syntax. My problem is that the query runs on the IDE but does not run on command or phpmyadmin. I´ve updated the query, check again and tell me if you se anything wrong. – Daniel Aug 09 '13 at 13:01
  • Even without syntax error I still get this erros on phpmyadmin: #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 14 – Daniel Aug 09 '13 at 13:23
0

Use DELIMITER.

DELIMITER $$

CREATE TRIGGER `teste` AFTER UPDATE ON `ilmug_virtuemart_products` FOR EACH ROW
BEGIN
   IF (NEW.origem_sync <> 0) THEN 
      INSERT INTO sincronizar (dataHora,
                               tipoMovimento,
                               entidade,
                               id,
                               version,
                               STATUS) 
                       VALUES (CURRENT_TIMESTAMP(),
                  'update',
                  'virtuemart_products',
                   NEW.virtuemart_product_id,
                   NEW.version,
                  'pendente');
   END IF;
END$$

DELIMITER ;
wchiquito
  • 16,177
  • 2
  • 34
  • 45
  • Then perhaps you should consider marking the answer as accepted, along with all the correct answer to the other questions you have asked. –  Nov 10 '15 at 03:17