-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- Trigger de DELETE tda_sga_comisiones
-- AFTER DELETE
-- Tabla: sga_comisiones
-- Version 3.0.0
-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

-- DROP FUNCTION ftda_sga_comisiones();
CREATE OR REPLACE FUNCTION ftda_sga_comisiones () RETURNS trigger AS 
$BODY$
BEGIN
   -- Borro tabla de cupos
   DELETE FROM sga_comisiones_cupo WHERE comision = OLD.comision;

   -- Borro el registro en la tabla de entidades..
   DELETE FROM sga_g3entidades WHERE entidad = OLD.entidad;
   RETURN OLD;
END;
$BODY$
LANGUAGE 'plpgsql';


-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- Trigger de DELETE sobre sga_comisiones
-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- DROP TRIGGER tda_sga_comisiones ON sga_comisiones RESTRICT;
CREATE TRIGGER tda_sga_comisiones 
    AFTER DELETE ON sga_comisiones
    FOR EACH ROW EXECUTE PROCEDURE ftda_sga_comisiones();
