1 trigger:

CREATE TRIGGER `after_insert_visits` AFTER INSERT ON `visits` FOR EACH ROW INSERT INTO `statistics` (`a_id`, `date` ,`visits`, `created`) VALUES (`NEW`.`a_id`, UNIX_TIMESTAMP(CURDATE()), 1, UNIX_TIMESTAMP()) ON DUPLICATE KEY UPDATE `visits`=`visits` + 1, `updated` = UNIX_TIMESTAMP() 

2 trigger:

 CREATE TRIGGER `before_insert_operations` BEFORE INSERT ON `operations` FOR EACH ROW DECLARE _typeName VARCHAR(32); DECLARE _subTypeName VARCHAR(32); 

When inserting a second error occurs:

 Данный запрос не был выполнен: "CREATE DEFINER=`root`@`localhost` TRIGGER `before_insert_operations` BEFORE INSERT ON `operations` FOR EACH ROW DECLARE _typeName VARCHAR(32); DECLARE _subTypeName VARCHAR(32); " Ответ MySQL: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DECLARE _typeName VARCHAR(32); DECLARE _subTypeName VARCHAR(32)' at line 3 

If you do this:

 CREATE TRIGGER `before_insert_operations` BEFORE INSERT ON `operations` FOR EACH ROW BEGIN DECLARE _typeName VARCHAR(32); DECLARE _subTypeName VARCHAR(32); END 

That is, to add BEGIN END , everything works, but why is that, because the first one works fine without BEGIN END ? triggers add with phpmyadmin 4.4

    1 answer 1

    The fact is that in the first trigger, all the logic was removed in one expression. In the second trigger, you have two expressions and need to be wrapped in the keywords BEGIN and END , so that the analyzer understands that they belong to the trigger, and not to the new SQL query.