0

我在尝试创建以下触发器时遇到问题:

CREATE TRIGGER loteria_loterias AFTER UPDATE ON loteria_loterias
FOR EACH ROW BEGIN
UPDATE
  loteria_loterias l
  JOIN loteria_tipos t
    ON l.tipo = t.id
SET
  NEW.fecha_fin = NEW.fecha_ini + interval t.duracion hour
WHERE c.cID=NEW.cID;
END

我对表格有以下定义:

CREATE TABLE `loteria_loterias` (
 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
 `tipo` int(11) unsigned NOT NULL,
 `fecha_ini` datetime NOT NULL,
 `fecha_fin` datetime DEFAULT NULL,
 `ganador` varchar(60) CHARACTER SET utf8 DEFAULT NULL,
 PRIMARY KEY (`id`),
 KEY `ganador` (`ganador`),
 KEY `tipo` (`tipo`),
 CONSTRAINT `loteria_loterias_ibfk_2` FOREIGN KEY (`tipo`) REFERENCES `loteria_tipos` (`id`),
 CONSTRAINT `loteria_loterias_ibfk_1` FOREIGN KEY (`ganador`) REFERENCES `tegm_users` (`user_login`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=latin1



CREATE TABLE `loteria_tipos` (
 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
 `nombre` varchar(60) NOT NULL,
 `coste` int(11) NOT NULL,
 `premio` int(11) NOT NULL,
 `duracion` int(11) NOT NULL COMMENT '(en horas)',
 `activa` tinyint(1) NOT NULL,
 `x` int(11) NOT NULL COMMENT '(coordenadas del cartel)',
 `y` int(11) NOT NULL COMMENT '(coordenadas del cartel)',
 `z` int(11) NOT NULL COMMENT '(coordenadas del cartel)',
 UNIQUE KEY `id` (`id`),
 KEY `id_2` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

根据 MySQL:

#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 9 
4

1 回答 1

1

您缺少ON关键字:

CREATE TRIGGER loteria_loterias AFTER UPDATE ON loteria_loterias
                                             ^^
于 2013-07-05T14:20:22.693 回答