-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- Trigger de INSERT tda_sga_alumnos_orient
-- TRIGGER AFTER DELETE
-- Tabla: sga_alumnos_orient
-- Version 3.0.0
-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

-- DROP FUNCTION ftda_sga_alumnos_orient();
CREATE OR REPLACE FUNCTION ftda_sga_alumnos_orient() RETURNS TRIGGER AS 
$BODY$
BEGIN
  -- Registro la baja de la orientacion
  INSERT INTO sga_alumnos_orient_mov (alumno, orientacion, fecha, tipo_movimiento)
       VALUES (OLD.alumno, OLD.orientacion, OLD.fecha, 'Baja');
  RETURN OLD;
END;
$BODY$ 
LANGUAGE plpgsql;


-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- Trigger de DELETE sobre sga_alumnos_orient
-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- DROP TRIGGER tda_sga_alumnos_orient ON sga_alumnos_orient RESTRICT;
CREATE TRIGGER tda_sga_alumnos_orient 
    AFTER DELETE ON sga_alumnos_orient
    FOR EACH ROW EXECUTE PROCEDURE ftda_sga_alumnos_orient();
