MySQL Forums
Forum List  »  Spanish

Definición de triggers a través de phpmyadmin!!!
Posted by: Juan Pablo Isler
Date: August 05, 2009 12:35AM

Hola, espero alguien pueda ayudarme con este asunto. Resulta que tengo definidos los siguientes Triggers:

//************Primer Trigger***********************
CREATE TRIGGER upd_ventasestacion BEFORE INSERT ON proyeccion
FOR EACH ROW
BEGIN
SET NEW.repoa := NEW.poa;
SET NEW.mar := 0;
UPDATE ventasestacion SET repoa = NEW.repoa WHERE idEds = NEW.idEds AND año = NEW.año AND mes = NEW.mes AND idProducto = NEW.idProducto;
UPDATE ventasestacion SET marpoa = NEW.marpoa WHERE idEds = NEW.idEds AND año = NEW.año AND mes = NEW.mes AND idProducto = NEW.idProducto;
END;

//************Segundo Trigger***********************
CREATE TRIGGER mod_ventasestacion BEFORE INSERT ON ventasestacion
FOR EACH ROW
BEGIN
DECLARE REPOA DECIMAL(15,5);
SELECT repoa INTO REPOA FROM proyeccion WHERE idEds = NEW.idEds AND año = NEW.año AND mes = NEW.mes AND idProducto = NEW.idProducto;
SET NEW.repoa := REPOA;
SELECT marpoa INTO MARPOA FROM proyeccion WHERE idEds = NEW.idEds AND año = NEW.año AND mes = NEW.mes AND idProducto = NEW.idProducto;
SET NEW.marpoa := MARPOA;
END;

//************Tercer Trigger***********************
CREATE TRIGGER mod_ventasestacion AFTER INSERT ON ventasestacion
FOR EACH ROW
BEGIN
IF NEW.mar > 0 THEN
UPDATE proyeccion SET mar = NEW.mar WHERE idEds = NEW.idEds AND año = NEW.año AND mes = NEW.mes AND idProducto = NEW.idProducto;
END IF;
END;

//************Cuarto Trigger***********************
CREATE TRIGGER upd_proyeccion AFTER UPDATE ON ventasestacion
FOR EACH ROW
BEGIN
UPDATE proyeccion SET repoa = NEW.repoa WHERE idEds = NEW.idEds AND año = NEW.año AND mes = NEW.mes AND idProducto = NEW.idProducto;
END;

Y para todos ellos obtengo el siguiente error al ejecutar las consultas:

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, la que corresponde a "BEGIN".

Aparte, tengo la duda de como declarar una variable decimal(15,1), en el segundo Trigger.

Las tablas son "ventasestacion" y "proyeccion". No estan escritos los delimiter debido a que los estoy ingresando a través de consultas por PhpMyAdmin.

Gracias de antemano.

Options: ReplyQuote


Subject
Views
Written By
Posted
Definición de triggers a través de phpmyadmin!!!
5072
August 05, 2009 12:35AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.