To avoid doing code validation, I would like mysql to insert a detail of a loan to create a trigger
to validate if cantidad de artículos
in tabla artículos
is greater than zero , let me update the table articles otherwise not update.
This is what I have done for the moment in phpmyadmin.
DROP TRIGGER IF EXISTS ACTUALIZAP_BI;
DELIMITER $$
CREATE TRIGGER ACTUALIZAP_BI BEFORE INSERT ON detalleprestamo FOR EACH ROW
BEGIN
DECLARE V = @SELECT cant_articulo FROM articulos WHERE id_articulo = new.idarticulo;
IF V > 0 THEN
DECLARE T = UPDATE articulos SET
cant_articulo = (cant_articulo - new.unidades) WHERE id_articulo = new.idarticulo;
ELSE
DECLARE T = FALSE;
END IF;
SELECT T;
END;
DELIMITER $$;