使用phpmyadmin在mysql数据库上设置触发器时出现语法错误

l5tcr1uw  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(188)

我在使用phpmyadmin设置mysql数据库触发器时遇到问题。这是扳机

DELIMITER //
CREATE TRIGGER triggerName
AFTER INSERT ON `tableToMonitor` FOR EACH ROW
BEGIN
   DECLARE `recordExists` TINYINT;
   IF NEW.`field1` = "stringValue" THEN
       SELECT COUNT(*)
       INTO `recordExists`
       FROM `table1`
       WHERE (`field2` = NEW.`field2`) AND (`field3` = NEW.`field3`);

       IF recordExists = 1 THEN
           UPDATE `table1`
           SET `field4` = 1 
           WHERE (`field2` = NEW.`field2`) AND (`field3` = NEW.`field3`);
       ELSE
           INSERT INTO table1 (`field2`, `field3`, `field4`, `field6`, `field7`, `field8`, `field9`)
           VALUES (NEW.`field2`, NEW.`field3`, 1, 0, 0, 0, 0);
       END IF;
    END IF;
END //

当我试图设置触发器时,出现以下错误:

1064-您的sql语法有错误;在第20行“//”附近,检查与mysql服务器版本相对应的手册,以获得正确的语法

我找不到错误,有人能帮我吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题