Sunteți pe pagina 1din 6

/// EMPLEADO INSERT///// CREATE OR REPLACE FUNCTION insert_empleado_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select* from empleado where

emp_cc=new.emp_cc) then raise exception 'El empleado ya existe..'; end if; return new; END; $$ LANGUAGE plpgsql; CREATE TRIGGER insert_empleado_before BEFORE INSERT ON empleado FOR EACH ROW EXECUTE PROCEDURE insert_empleado_before(); /// EMPLEADO UPDATE///// CREATE OR REPLACE FUNCTION update_empleado_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select * from empleado where emp_cc=new.emp_cc and emp_cc<>old.emp_cc) then raise exception 'LA CEDULA DEL EMPLEADO NO SE PUEDE CAMBIAR, YA EXISTE OTRO REGI STRO CON LA IDENTIFICACION'; end if; return new; END; $$ LANGUAGE plpgsql; CREATE TRIGGER update_empleado_before BEFORE UPDATE ON empleado FOR EACH ROW EXECUTE PROCEDURE update_empleado_before(); /// EMPLEADO DELETE///// CREATE OR REPLACE FUNCTION delete_empleado_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select * from hisxmov where old.emp_cc=hxm_empcc)then raise exception ' NO SE PUEDE ELIMINAR EL EMPLEADO'; end if; return old; END; $$ LANGUAGE plpgsql; CREATE TRIGGER delete_empleado_before BEFORE DELETE ON empleado FOR EACH ROW EXECUTE PROCEDURE delete_empleado_before(); /// CUENTA INSERT///// CREATE OR REPLACE FUNCTION insert_cuenta_before() RETURNS TRIGGER AS $$ DECLARE BEGIN

if exists(select * from cuenta where cue_num=new.cue_num) then raise exception 'La cuenta ya existe..'; end if; return new; END; $$ LANGUAGE plpgsql; CREATE TRIGGER insert_cuenta_before BEFORE INSERT ON cuenta FOR EACH ROW EXECUTE PROCEDURE insert_cuenta_before(); /// CUENTA UPDATE///// CREATE OR REPLACE FUNCTION update_cuenta_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select * from cuenta where cue_num=new.cue_num and cue_num<>old.cue_nu m)then raise exception 'LA CUENTA NO SE PUEDE CAMBIAR, YA EXISTE OTRA CUENTA CON LA IDE NTIFICACION'; end if; return new; END; $$ LANGUAGE plpgsql; CREATE TRIGGER update_cuenta_before BEFORE UPDATE ON cuenta FOR EACH ROW EXECUTE PROCEDURE update_cuenta_before(); /// CUENTA DELETE///// CREATE OR REPLACE FUNCTION delete_cuenta_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select * from movimiento where old.cue_num=mov_cuenum)then raise exception ' NO SE PUEDE ELIMINAR ESTA CUENTA'; end if; return old; END; $$ LANGUAGE plpgsql; CREATE TRIGGER delete_cuenta_before BEFORE DELETE ON cuenta FOR EACH ROW EXECUTE PROCEDURE delete_cuenta_before(); /// MOVIMIENTO INSERT///// CREATE OR REPLACE FUNCTION insert_movimiento_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select* from movimiento where mov_num=new.mov_num) then raise exception 'Este movimiento ya existe..'; end if; return new; END; $$ LANGUAGE plpgsql;

CREATE TRIGGER insert_movimiento_before BEFORE INSERT ON movimiento FOR EACH ROW EXECUTE PROCEDURE insert_movimiento_before(); /// MOVIMIENTO UPDATE///// CREATE OR REPLACE FUNCTION update_movimiento_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select * from where mov_num=new.mov_num and mov_num<>old.mov_num)then raise exception 'ESTE MOVIMIENTO NO SE PUEDE REALIZAR, YA EXISTE ESTE MOVIMIENTO '; end if; return new; END; $$ LANGUAGE plpgsql; CREATE TRIGGER update_movimiento_before BEFORE UPDATE ON movimiento FOR EACH ROW EXECUTE PROCEDURE update_movimiento_before(); /// MOVIMIENTO DELETE///// CREATE OR REPLACE FUNCTION delete_movimiento_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select * from hisxmov where old.mov_num=hxm_movnum)then raise exception ' NO SE PUEDE ELIMINAR ESTE MOVIMIENTO'; end if; return old; END; $$ LANGUAGE plpgsql; CREATE TRIGGER delete_movimiento_before BEFORE DELETE ON movimiento FOR EACH ROW EXECUTE PROCEDURE delete_movimiento_before(); /// BANCO INSERT///// CREATE OR REPLACE FUNCTION insert_banco_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select* from banco where ban_nit=new.ban_nit) then raise exception 'Este NIT ya existe..'; end if; return new; END; $$ LANGUAGE plpgsql; CREATE TRIGGER insert_banco_before BEFORE INSERT ON banco FOR EACH ROW EXECUTE PROCEDURE insert_banco_before(); /// BANCO UPDATE///// CREATE OR REPLACE FUNCTION update_banco_before() RETURNS TRIGGER AS $$ DECLARE BEGIN

if exists(select * from where ban_nit=new.ban_nit and ban_nit<>old.ban_nit)then raise exception 'ESTE NIT NO SE PUUEDE CREAR, YA EXISTE ESTE NIT'; end if; return new; END; $$ LANGUAGE plpgsql; CREATE TRIGGER update_banco_before BEFORE UPDATE ON banco FOR EACH ROW EXECUTE PROCEDURE update_banco_before(); // BANCO DELETE///// CREATE OR REPLACE FUNCTION delete_banco_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select * from cuenta where old.ban_nit=cue_bannit)then raise exception ' NO SE PUEDE ELIMINAR ESTE NIT'; end if; return old; END; $$ LANGUAGE plpgsql; CREATE TRIGGER delete_banco_before BEFORE DELETE ON banco FOR EACH ROW EXECUTE PROCEDURE delete_banco_before(); /// TIPOCTA INSERT///// CREATE OR REPLACE FUNCTION insert_tipocta_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select* from tipocta where tipc_id=new.tipc_id) then raise exception 'YA EXISTE ESTE TIPO DE CUENTA..'; end if; return new; END; $$ LANGUAGE plpgsql; CREATE TRIGGER insert_tipocta_before BEFORE INSERT ON tipocta FOR EACH ROW EXECUTE PROCEDURE insert_tipocta_before(); /// TIPOCTA UPDATE///// CREATE OR REPLACE FUNCTION update_banco_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select * from where tipc_id=new.tipc_id and tipc_id<>old.tipc_id)then raise exception 'ESTE TIPO DE CUENTA NO SE PUEDE CREAR, YA EXISTE'; end if; return new; END; $$ LANGUAGE plpgsql; CREATE TRIGGER update_tipocta_before BEFORE UPDATE ON tipocta FOR EACH ROW

EXECUTE PROCEDURE update_tipocta_before(); // TIPOCTA DELETE///// CREATE OR REPLACE FUNCTION delete_banco_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select * from cuenta where old.tipocta=cue_tipcid)then raise exception ' NO SE PUEDE ELIMINAR ESTE TIPO CUENTA'; end if; return old; END; $$ LANGUAGE plpgsql; CREATE TRIGGER delete_banco_before BEFORE DELETE ON tipocta FOR EACH ROW EXECUTE PROCEDURE delete_banco_before(); /// TIPOMOV INSERT///// CREATE OR REPLACE FUNCTION insert_tipomov_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select* from tipocta where tipm_id=new.tipm_id) then raise exception 'YA EXISTE ESTE TIPO DE MOVIMIENTO..'; end if; return new; END; $$ LANGUAGE plpgsql; CREATE TRIGGER insert_tipomov_before BEFORE INSERT ON tipomov FOR EACH ROW EXECUTE PROCEDURE insert_tipomov_before(); /// TIPOCTA UPDATE///// CREATE OR REPLACE FUNCTION update_banco_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select * from where tipm_id=new.tipm_id and tipm_id<>old.tipm_id)then raise exception 'ESTE TIPO DE CUENTA NO SE PUEDE CREAR, YA EXISTE'; end if; return new; END; $$ LANGUAGE plpgsql; CREATE TRIGGER update_tipomov_before BEFORE UPDATE ON tipomov FOR EACH ROW EXECUTE PROCEDURE update_tipomov_before(); // TIPOCTA DELETE///// CREATE OR REPLACE FUNCTION delete_banco_before() RETURNS TRIGGER AS $$ DECLARE BEGIN if exists(select * from movimiento where old.tipomov=mov_tipmid)then raise exception ' NO SE PUEDE ELIMINAR ESTE TIPO CUENTA'; end if; return old;

END; $$ LANGUAGE plpgsql; CREATE TRIGGER delete_banco_before BEFORE DELETE ON tipomov FOR EACH ROW EXECUTE PROCEDURE delete_banco_before();