-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- Trigger de DELETE: tdb_sga_actas
-- BEFORE DELETE
-- Tabla: sga_actas
-- Version: 3.0.0
-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

CREATE OR REPLACE FUNCTION ftdb_sga_actas () RETURNS trigger AS 
$BODY$

BEGIN
   -- No se permite borrar un acta si esta cerrada o dada de baja
   IF OLD.estado = 'C' THEN
      raise exception 'No se puede sacar alumnos del acta porque esta Cerrada';
   ELSEIF OLD.estado = 'B' THEN
      raise exception 'No se puede sacar alumnos del acta porque esta Anulada';
   END IF ;
   
   RETURN OLD;
END;
$BODY$
LANGUAGE 'plpgsql';


-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- Trigger de DELETE sobre sga_actas
-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- DROP TRIGGER tdb_sga_actas ON sga_actas RESTRICT;
CREATE TRIGGER tdb_sga_actas
       BEFORE DELETE ON sga_actas 
       FOR EACH ROW EXECUTE PROCEDURE ftdb_sga_actas();
