alter table convenios alter con_integracaohospital type text; insert into atualizacoes(atu_nome) values ('v21020001_020221.sql'); alter table paciente add pac_tokenpushcelular varchar(200); insert into atualizacoes(atu_nome) values ('v21020002_120221.sql'); alter table lanctocaixa add lcx_pix varchar(50); insert into atualizacoes(atu_nome) values ('v21020003_220221.sql'); alter table lotefilial add fil_coddestino integer; create index xif5lotefilial on lotefilial ( fil_coddestino ); alter table lotefilialexamerequisicao add lfe_datatransportesaida timestamp, add lfe_datatransportechegada timestamp, add usr_codtransportesaida varchar(20), add usr_codtransportechegada varchar(20); create index xif3lotefilialexamerequisicao on lotefilialexamerequisicao ( usr_codtransportesaida ); create index xif4lotefilialexamerequisicao on lotefilialexamerequisicao ( usr_codtransportechegada ); drop function fn_td_filiais_postocoleta() cascade; create function fn_td_filiais_postocoleta() returns opaque as ' declare numrows integer; begin select count(*) into numrows from lotefilial where lotefilial.fil_coddestino = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilial.''; end if; select count(*) into numrows from preagendamento where preagendamento.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamento.''; end if; select count(*) into numrows from integracaosave where integracaosave.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela integracaosave.''; end if; select count(*) into numrows from paciente where paciente.fil_codorigem = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; select count(*) into numrows from logpushapp where logpushapp.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logpushapp.''; end if; select count(*) into numrows from motivorecoleta where motivorecoleta.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela motivorecoleta.''; end if; delete from logvalidalote where logvalidalote.fil_codigo = old.fil_codigo; select count(*) into numrows from ambbpa where ambbpa.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela ambbpa.''; end if; select count(*) into numrows from categoriaprodutoalimentos where categoriaprodutoalimentos.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela categoriaprodutoalimentos.''; end if; delete from responsavelcertificado where responsavelcertificado.fil_codigo = old.fil_codigo; select count(*) into numrows from origemnaoconformidade where origemnaoconformidade.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela origemnaoconformidade.''; end if; select count(*) into numrows from filialemailaniversario where filialemailaniversario.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filialemailaniversario.''; end if; select count(*) into numrows from filialsmsaniversario where filialsmsaniversario.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filialsmsaniversario.''; end if; select count(*) into numrows from logemail where logemail.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logemail.''; end if; delete from filialsmsresumo where filialsmsresumo.fil_codigo = old.fil_codigo; select count(*) into numrows from lanctocaixa where lanctocaixa.fil_codentrefilial = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctocaixa.''; end if; select count(*) into numrows from lotefilial where lotefilial.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilial.''; end if; select count(*) into numrows from taxa where taxa.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela taxa.''; end if; select count(*) into numrows from logoffline where logoffline.fil_coddestino = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logoffline.''; end if; select count(*) into numrows from logoffline where logoffline.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logoffline.''; end if; select count(*) into numrows from pais where pais.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pais.''; end if; select count(*) into numrows from logsms where logsms.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logsms.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from acaonaoconformidade where acaonaoconformidade.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela acaonaoconformidade.''; end if; select count(*) into numrows from procedencianaoconformidade where procedencianaoconformidade.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela procedencianaoconformidade.''; end if; select count(*) into numrows from banhomaria where banhomaria.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela banhomaria.''; end if; select count(*) into numrows from identificadorlamina where identificadorlamina.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela identificadorlamina.''; end if; select count(*) into numrows from materiallote where materiallote.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from examerequisicaohash where examerequisicaohash.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohash.''; end if; select count(*) into numrows from motivoalteracao where motivoalteracao.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela motivoalteracao.''; end if; select count(*) into numrows from tipomaterialcoleta where tipomaterialcoleta.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela tipomaterialcoleta.''; end if; select count(*) into numrows from salaatendimento where salaatendimento.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela salaatendimento.''; end if; select count(*) into numrows from agendamento where agendamento.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from requisicaoweb where requisicaoweb.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoweb.''; end if; select count(*) into numrows from lanctoestoquecmc where lanctoestoquecmc.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoquecmc.''; end if; select count(*) into numrows from lanctoestoqueueps where lanctoestoqueueps.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoqueueps.''; end if; select count(*) into numrows from lanctoestoquepeps where lanctoestoquepeps.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoquepeps.''; end if; select count(*) into numrows from contrassenharequisicao where contrassenharequisicao.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrassenharequisicao.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from exportaintegracaohospital where exportaintegracaohospital.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela exportaintegracaohospital.''; end if; select count(*) into numrows from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; select count(*) into numrows from examerequisicaosetor where examerequisicaosetor.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosetor.''; end if; select count(*) into numrows from materialenviado where materialenviado.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialenviado.''; end if; select count(*) into numrows from rota where rota.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela rota.''; end if; select count(*) into numrows from montagemkit where montagemkit.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela montagemkit.''; end if; select count(*) into numrows from transfestoque where transfestoque.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoque.''; end if; select count(*) into numrows from orcamento where orcamento.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamento.''; end if; select count(*) into numrows from estoquemanual where estoquemanual.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela estoquemanual.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from conferenciaestoque where conferenciaestoque.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from conferenciaentrada where conferenciaentrada.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaentrada.''; end if; select count(*) into numrows from pedido where pedido.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from cotacao where cotacao.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela cotacao.''; end if; select count(*) into numrows from cfop where cfop.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela cfop.''; end if; select count(*) into numrows from celulaestoque where celulaestoque.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela celulaestoque.''; end if; select count(*) into numrows from unidadesaude where unidadesaude.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela unidadesaude.''; end if; select count(*) into numrows from estantes where estantes.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela estantes.''; end if; select count(*) into numrows from geladeiras where geladeiras.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela geladeiras.''; end if; delete from usuariofilial where usuariofilial.fil_codigo = old.fil_codigo; select count(*) into numrows from origemplanocusto where origemplanocusto.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela origemplanocusto.''; end if; select count(*) into numrows from filialimposto where filialimposto.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filialimposto.''; end if; select count(*) into numrows from embalagemproduto where embalagemproduto.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela embalagemproduto.''; end if; select count(*) into numrows from notafiscal where notafiscal.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from servico where servico.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela servico.''; end if; select count(*) into numrows from baixa where baixa.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela baixa.''; end if; select count(*) into numrows from receberpagar where receberpagar.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from entidade where entidade.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela entidade.''; end if; select count(*) into numrows from motivoscancelamentos where motivoscancelamentos.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela motivoscancelamentos.''; end if; select count(*) into numrows from formapagto where formapagto.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela formapagto.''; end if; select count(*) into numrows from especie where especie.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela especie.''; end if; select count(*) into numrows from series where series.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela series.''; end if; delete from filiaisweb where filiaisweb.fil_kodigo = old.fil_codigo; delete from filiaisweb where filiaisweb.fil_codigo = old.fil_codigo; select count(*) into numrows from labexterno where labexterno.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexterno.''; end if; select count(*) into numrows from loteexterno where loteexterno.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from log where log.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela log.''; end if; select count(*) into numrows from alahospital where alahospital.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela alahospital.''; end if; select count(*) into numrows from loteapoio where loteapoio.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteapoio.''; end if; select count(*) into numrows from exportaapoio where exportaapoio.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela exportaapoio.''; end if; select count(*) into numrows from exportafiliais where exportafiliais.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela exportafiliais.''; end if; select count(*) into numrows from requisicao where requisicao.fil_codcopia = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from filiaisexamesexportar where filiaisexamesexportar.fil_coddestino = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiaisexamesexportar.''; end if; select count(*) into numrows from contrasenha where contrasenha.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrasenha.''; end if; select count(*) into numrows from exportaweb where exportaweb.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela exportaweb.''; end if; select count(*) into numrows from interface where interface.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela interface.''; end if; select count(*) into numrows from banco where banco.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela banco.''; end if; select count(*) into numrows from agencia where agencia.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agencia.''; end if; select count(*) into numrows from historicopadrao where historicopadrao.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela historicopadrao.''; end if; select count(*) into numrows from prioridade where prioridade.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela prioridade.''; end if; select count(*) into numrows from destino where destino.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela destino.''; end if; select count(*) into numrows from grupo where grupo.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela grupo.''; end if; select count(*) into numrows from feriados where feriados.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela feriados.''; end if; select count(*) into numrows from especialidades where especialidades.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela especialidades.''; end if; select count(*) into numrows from coletas where coletas.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela coletas.''; end if; select count(*) into numrows from tabelaprecoexames where tabelaprecoexames.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela tabelaprecoexames.''; end if; select count(*) into numrows from tipomaterial where tipomaterial.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela tipomaterial.''; end if; select count(*) into numrows from unidademedida where unidademedida.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela unidademedida.''; end if; select count(*) into numrows from situacao where situacao.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela situacao.''; end if; select count(*) into numrows from principios where principios.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela principios.''; end if; select count(*) into numrows from medicamentos where medicamentos.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela medicamentos.''; end if; select count(*) into numrows from layout where layout.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela layout.''; end if; select count(*) into numrows from metodologia where metodologia.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela metodologia.''; end if; select count(*) into numrows from recipientes where recipientes.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela recipientes.''; end if; select count(*) into numrows from cidades where cidades.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela cidades.''; end if; select count(*) into numrows from bairro where bairro.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela bairro.''; end if; select count(*) into numrows from materialcoleta where materialcoleta.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialcoleta.''; end if; select count(*) into numrows from prazoentrega where prazoentrega.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela prazoentrega.''; end if; select count(*) into numrows from historicos where historicos.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela historicos.''; end if; select count(*) into numrows from lanctocaixa where lanctocaixa.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctocaixa.''; end if; select count(*) into numrows from centrocusto where centrocusto.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela centrocusto.''; end if; select count(*) into numrows from planoconta where planoconta.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela planoconta.''; end if; select count(*) into numrows from contacorrente where contacorrente.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contacorrente.''; end if; select count(*) into numrows from material where material.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela material.''; end if; select count(*) into numrows from requisicao where requisicao.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from medico where medico.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela medico.''; end if; select count(*) into numrows from convenios where convenios.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenios.''; end if; delete from exames where exames.fil_codigo = old.fil_codigo; select count(*) into numrows from fatura where fatura.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from setores where setores.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setores.''; end if; select count(*) into numrows from paciente where paciente.fil_codigo = old.fil_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; return old; end;' language 'plpgsql'; create trigger td_filiais_postocoleta after delete on filiais_postocoleta for each row execute procedure fn_td_filiais_postocoleta(); drop function fn_ti_filiais_postocoleta() cascade; create function fn_ti_filiais_postocoleta() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from labexterno where new.fil_codigo = labexterno.fil_codigo and new.lae_codigo = labexterno.lae_codigo; tmp:=''labexterno|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''lae_codigo='' || new.lae_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.lae_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela labexterno. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codcompras = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcompras || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcompras is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codestoque = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codestoque || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codestoque is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from bairro where new.fil_codigo = bairro.fil_codigo and new.bai_codigo = bairro.bai_codigo; tmp:=''bairro|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''bai_codigo='' || new.bai_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.bai_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela bairro. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from cidades where new.fil_codigo = cidades.fil_codigo and new.cid_codigo = cidades.cid_codigo; tmp:=''cidades|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''cid_codigo='' || new.cid_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.cid_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela cidades. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_filiais_postocoleta after insert on filiais_postocoleta for each row execute procedure fn_ti_filiais_postocoleta(); drop function fn_tu_filiais_postocoleta() cascade; create function fn_tu_filiais_postocoleta() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo) then select count(*) from lotefilial where lotefilial.fil_coddestino = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from preagendamento where preagendamento.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamento.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from integracaosave where integracaosave.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela integracaosave.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from paciente where paciente.fil_codorigem = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from logpushapp where logpushapp.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logpushapp.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from motivorecoleta where motivorecoleta.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela motivorecoleta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from logvalidalote where logvalidalote.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logvalidalote.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from ambbpa where ambbpa.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela ambbpa.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from categoriaprodutoalimentos where categoriaprodutoalimentos.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela categoriaprodutoalimentos.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from responsavelcertificado where responsavelcertificado.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela responsavelcertificado.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from origemnaoconformidade where origemnaoconformidade.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela origemnaoconformidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from filialemailaniversario where filialemailaniversario.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filialemailaniversario.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from filialsmsaniversario where filialsmsaniversario.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filialsmsaniversario.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from logemail where logemail.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logemail.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from filialsmsresumo where filialsmsresumo.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filialsmsresumo.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from lanctocaixa where lanctocaixa.fil_codentrefilial = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctocaixa.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from lotefilial where lotefilial.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from taxa where taxa.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela taxa.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from logoffline where logoffline.fil_coddestino = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logoffline.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from logoffline where logoffline.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logoffline.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from pais where pais.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pais.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from logsms where logsms.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logsms.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from naoconformidade where naoconformidade.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from acaonaoconformidade where acaonaoconformidade.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela acaonaoconformidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from procedencianaoconformidade where procedencianaoconformidade.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela procedencianaoconformidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from banhomaria where banhomaria.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela banhomaria.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from identificadorlamina where identificadorlamina.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela identificadorlamina.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from materiallote where materiallote.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from examerequisicaohash where examerequisicaohash.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohash.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from motivoalteracao where motivoalteracao.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela motivoalteracao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from tipomaterialcoleta where tipomaterialcoleta.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela tipomaterialcoleta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from salaatendimento where salaatendimento.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela salaatendimento.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from agendamento where agendamento.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from requisicaoweb where requisicaoweb.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoweb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from lanctoestoquecmc where lanctoestoquecmc.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoquecmc.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from lanctoestoqueueps where lanctoestoqueueps.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoqueueps.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from lanctoestoquepeps where lanctoestoquepeps.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoquepeps.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from contrassenharequisicao where contrassenharequisicao.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrassenharequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from exportaintegracaohospital where exportaintegracaohospital.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exportaintegracaohospital.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from examerequisicaosetor where examerequisicaosetor.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosetor.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from materialenviado where materialenviado.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialenviado.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from rota where rota.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela rota.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from montagemkit where montagemkit.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela montagemkit.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from transfestoque where transfestoque.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoque.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from orcamento where orcamento.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamento.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from estoquemanual where estoquemanual.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela estoquemanual.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from conferenciaestoque where conferenciaestoque.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaestoque.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from lanctoestoque where lanctoestoque.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from conferenciaentrada where conferenciaentrada.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaentrada.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from pedido where pedido.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from cotacao where cotacao.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela cotacao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from cfop where cfop.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela cfop.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from celulaestoque where celulaestoque.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela celulaestoque.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from unidadesaude where unidadesaude.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela unidadesaude.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from estantes where estantes.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela estantes.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from geladeiras where geladeiras.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela geladeiras.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from origemplanocusto where origemplanocusto.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela origemplanocusto.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from filialimposto where filialimposto.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filialimposto.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from embalagemproduto where embalagemproduto.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela embalagemproduto.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from notafiscal where notafiscal.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from servico where servico.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela servico.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from baixa where baixa.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela baixa.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from receberpagar where receberpagar.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from entidade where entidade.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela entidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from motivoscancelamentos where motivoscancelamentos.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela motivoscancelamentos.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from formapagto where formapagto.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela formapagto.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from especie where especie.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela especie.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from series where series.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela series.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from filiaisweb where filiaisweb.fil_kodigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiaisweb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from filiaisweb where filiaisweb.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiaisweb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from labexterno where labexterno.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from loteexterno where loteexterno.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from log where log.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela log.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from alahospital where alahospital.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela alahospital.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from loteapoio where loteapoio.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteapoio.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from exportaapoio where exportaapoio.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exportaapoio.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from exportafiliais where exportafiliais.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exportafiliais.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from requisicao where requisicao.fil_codcopia = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from filiaisexamesexportar where filiaisexamesexportar.fil_coddestino = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiaisexamesexportar.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from contrasenha where contrasenha.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrasenha.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from exportaweb where exportaweb.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exportaweb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from interface where interface.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela interface.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from banco where banco.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela banco.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from agencia where agencia.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agencia.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from historicopadrao where historicopadrao.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela historicopadrao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from prioridade where prioridade.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela prioridade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from destino where destino.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela destino.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from grupo where grupo.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela grupo.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from feriados where feriados.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela feriados.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from especialidades where especialidades.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela especialidades.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from coletas where coletas.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela coletas.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from tabelaprecoexames where tabelaprecoexames.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela tabelaprecoexames.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from tipomaterial where tipomaterial.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela tipomaterial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from unidademedida where unidademedida.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela unidademedida.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from situacao where situacao.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela situacao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from principios where principios.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela principios.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from medicamentos where medicamentos.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela medicamentos.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from layout where layout.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela layout.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from metodologia where metodologia.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela metodologia.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from recipientes where recipientes.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela recipientes.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from cidades where cidades.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela cidades.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from bairro where bairro.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela bairro.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from materialcoleta where materialcoleta.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialcoleta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from prazoentrega where prazoentrega.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela prazoentrega.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from historicos where historicos.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela historicos.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from lanctocaixa where lanctocaixa.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctocaixa.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from centrocusto where centrocusto.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela centrocusto.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from planoconta where planoconta.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela planoconta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from contacorrente where contacorrente.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contacorrente.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from material where material.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela material.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from requisicao where requisicao.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from medico where medico.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela medico.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from convenios where convenios.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenios.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from exames where exames.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exames.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from fatura where fatura.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from setores where setores.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setores.''; end if; end if; if (old.fil_codigo <> new.fil_codigo) then select count(*) from paciente where paciente.fil_codigo = old.fil_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; select count(*) into numrows from labexterno where new.fil_codigo = labexterno.fil_codigo and new.lae_codigo = labexterno.lae_codigo; tmp:=''labexterno|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''lae_codigo='' || new.lae_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.lae_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela labexterno. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codcompras = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcompras || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcompras is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codestoque = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codestoque || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codestoque is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from bairro where new.fil_codigo = bairro.fil_codigo and new.bai_codigo = bairro.bai_codigo; tmp:=''bairro|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''bai_codigo='' || new.bai_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.bai_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela bairro. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from cidades where new.fil_codigo = cidades.fil_codigo and new.cid_codigo = cidades.cid_codigo; tmp:=''cidades|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''cid_codigo='' || new.cid_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.cid_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela cidades. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_filiais_postocoleta after update on filiais_postocoleta for each row execute procedure fn_tu_filiais_postocoleta(); drop function fn_td_lotefilial() cascade; create function fn_td_lotefilial() returns opaque as ' declare numrows integer; begin delete from lotefilialrequisicao where lotefilialrequisicao.fil_codigo = old.fil_codigo and lotefilialrequisicao.lfi_codigo = old.lfi_codigo; return old; end;' language 'plpgsql'; create trigger td_lotefilial after delete on lotefilial for each row execute procedure fn_td_lotefilial(); drop function fn_ti_lotefilial() cascade; create function fn_ti_lotefilial() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from filiais_postocoleta where new.fil_coddestino = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_coddestino || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_coddestino is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from estacoes where new.est_codigo = estacoes.est_codigo; tmp:=''estacoes|''; tmp:=tmp || ''est_codigo='' || new.est_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.est_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela estacoes. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codrecebeu = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codrecebeu || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codrecebeu is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codenviou = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codenviou || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codenviou is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_lotefilial after insert on lotefilial for each row execute procedure fn_ti_lotefilial(); drop function fn_tu_lotefilial() cascade; create function fn_tu_lotefilial() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.lfi_codigo <> new.lfi_codigo) then select count(*) from lotefilialrequisicao where lotefilialrequisicao.fil_codigo = old.fil_codigo and lotefilialrequisicao.lfi_codigo = old.lfi_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilialrequisicao.''; end if; end if; select count(*) into numrows from filiais_postocoleta where new.fil_coddestino = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_coddestino || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_coddestino is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from estacoes where new.est_codigo = estacoes.est_codigo; tmp:=''estacoes|''; tmp:=tmp || ''est_codigo='' || new.est_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.est_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela estacoes. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codrecebeu = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codrecebeu || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codrecebeu is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codenviou = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codenviou || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codenviou is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_lotefilial after update on lotefilial for each row execute procedure fn_tu_lotefilial(); drop function fn_ti_lotefilialexamerequisicao() cascade; create function fn_ti_lotefilialexamerequisicao() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_codtransportechegada = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtransportechegada || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtransportechegada is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codtransportesaida = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtransportesaida || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtransportesaida is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from examerequisicao where new.fil_codigo = examerequisicao.fil_codigo and new.exa_codigo = examerequisicao.exa_codigo and new.mco_codigo = examerequisicao.mco_codigo and new.req_codigo = examerequisicao.req_codigo; tmp:=''examerequisicao|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=tmp || ''req_codigo='' || new.req_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela examerequisicao. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from lotefilialrequisicao where new.fil_codigo = lotefilialrequisicao.fil_codigo and new.lfi_codigo = lotefilialrequisicao.lfi_codigo and new.req_codigo = lotefilialrequisicao.req_codigo; tmp:=''lotefilialrequisicao|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''lfi_codigo='' || new.lfi_codigo || ''|''; tmp:=tmp || ''req_codigo='' || new.req_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela lotefilialrequisicao. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_lotefilialexamerequisicao after insert on lotefilialexamerequisicao for each row execute procedure fn_ti_lotefilialexamerequisicao(); drop function fn_tu_lotefilialexamerequisicao() cascade; create function fn_tu_lotefilialexamerequisicao() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_codtransportechegada = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtransportechegada || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtransportechegada is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codtransportesaida = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtransportesaida || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtransportesaida is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from examerequisicao where new.fil_codigo = examerequisicao.fil_codigo and new.exa_codigo = examerequisicao.exa_codigo and new.mco_codigo = examerequisicao.mco_codigo and new.req_codigo = examerequisicao.req_codigo; tmp:=''examerequisicao|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=tmp || ''req_codigo='' || new.req_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela examerequisicao. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from lotefilialrequisicao where new.fil_codigo = lotefilialrequisicao.fil_codigo and new.lfi_codigo = lotefilialrequisicao.lfi_codigo and new.req_codigo = lotefilialrequisicao.req_codigo; tmp:=''lotefilialrequisicao|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''lfi_codigo='' || new.lfi_codigo || ''|''; tmp:=tmp || ''req_codigo='' || new.req_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela lotefilialrequisicao. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_lotefilialexamerequisicao after update on lotefilialexamerequisicao for each row execute procedure fn_tu_lotefilialexamerequisicao(); drop function fn_td_usuario() cascade; create function fn_td_usuario() returns opaque as ' declare numrows integer; begin select count(*) into numrows from lotefilialexamerequisicao where lotefilialexamerequisicao.usr_codtransportechegada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilialexamerequisicao.''; end if; select count(*) into numrows from lotefilialexamerequisicao where lotefilialexamerequisicao.usr_codtransportesaida = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilialexamerequisicao.''; end if; select count(*) into numrows from historicopoliticaweb where historicopoliticaweb.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela historicopoliticaweb.''; end if; select count(*) into numrows from preagendamentoevento where preagendamentoevento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamentoevento.''; end if; select count(*) into numrows from labexternologintegracao where labexternologintegracao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexternologintegracao.''; end if; select count(*) into numrows from labexternoversaotermo where labexternoversaotermo.usr_codaceite = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexternoversaotermo.''; end if; select count(*) into numrows from preagendamento where preagendamento.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamento.''; end if; select count(*) into numrows from preagendamento where preagendamento.usr_codagendou = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamento.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_coddialsist = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from integracaosave where integracaosave.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela integracaosave.''; end if; select count(*) into numrows from interfaceexamereagente where interfaceexamereagente.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela interfaceexamereagente.''; end if; select count(*) into numrows from examerequisicaohistoricoentrega where examerequisicaohistoricoentrega.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricoentrega.''; end if; select count(*) into numrows from requisicaopaginasimpressas where requisicaopaginasimpressas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaopaginasimpressas.''; end if; select count(*) into numrows from tabelaprecoexamesusuario where tabelaprecoexamesusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela tabelaprecoexamesusuario.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codenvioemail = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from materialusuario where materialusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialusuario.''; end if; select count(*) into numrows from logids where logids.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logids.''; end if; select count(*) into numrows from logvalidalotematerial where logvalidalotematerial.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logvalidalotematerial.''; end if; select count(*) into numrows from material where material.usr_codavisolote = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela material.''; end if; delete from usuariosenhas where usuariosenhas.usr_codigo = old.usr_codigo; select count(*) into numrows from pacienteimagens where pacienteimagens.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pacienteimagens.''; end if; select count(*) into numrows from requisicaoimagens where requisicaoimagens.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoimagens.''; end if; select count(*) into numrows from orcamentoconvenio where orcamentoconvenio.usr_coddesconto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamentoconvenio.''; end if; select count(*) into numrows from requisicao where requisicao.usr_coddesconto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicaoetiquetas where examerequisicaoetiquetas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaoetiquetas.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codduplaconferencia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteexternorequisicao where loteexternorequisicao.usr_codestorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexternorequisicao.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codestorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from materiallotehistorico where materiallotehistorico.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallotehistorico.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codaberturainicial = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codfechado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codaberto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; delete from responsavelcertificado where responsavelcertificado.usr_codigo = old.usr_codigo; select count(*) into numrows from requisicao where requisicao.usr_codelegibilidade = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codsolicitadotiss = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codcoletar = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from transfestoquematerial where transfestoquematerial.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoquematerial.''; end if; select count(*) into numrows from transfestoque where transfestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoque.''; end if; select count(*) into numrows from examerequisicaodadosbrutos where examerequisicaodadosbrutos.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaodadosbrutos.''; end if; select count(*) into numrows from examerequisicaoincerteza where examerequisicaoincerteza.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaoincerteza.''; end if; select count(*) into numrows from setoresnaoconformidadeusuario where setoresnaoconformidadeusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setoresnaoconformidadeusuario.''; end if; select count(*) into numrows from setoresnaoconformidade where setoresnaoconformidade.usr_codresponsavelsetor = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setoresnaoconformidade.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtransportechegada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtransportesaida = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from lotefilial where lotefilial.usr_codrecebeu = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilial.''; end if; select count(*) into numrows from lotefilial where lotefilial.usr_codenviou = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilial.''; end if; select count(*) into numrows from logoffline where logoffline.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logoffline.''; end if; select count(*) into numrows from usuariologin where usuariologin.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuariologin.''; end if; select count(*) into numrows from acoesnaoconformidade where acoesnaoconformidade.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela acoesnaoconformidade.''; end if; select count(*) into numrows from orcamentolog where orcamentolog.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamentolog.''; end if; select count(*) into numrows from orcamento where orcamento.usr_codaprovado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamento.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codconclusao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codanalise = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codregistro = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from labexterno where labexterno.usr_codconferir = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexterno.''; end if; select count(*) into numrows from banhomariatemperatura where banhomariatemperatura.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela banhomariatemperatura.''; end if; select count(*) into numrows from banhomaria where banhomaria.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela banhomaria.''; end if; select count(*) into numrows from filiais_postocoleta where filiais_postocoleta.usr_codcompras = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiais_postocoleta.''; end if; select count(*) into numrows from filiais_postocoleta where filiais_postocoleta.usr_codestoque = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiais_postocoleta.''; end if; select count(*) into numrows from examerequisicaolaminas where examerequisicaolaminas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaolaminas.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codhorarioanexado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codbloqueado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codremovido = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from examerequisicaohash where examerequisicaohash.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohash.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codfinalizado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codemcoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codremarcado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from requisicaolog where requisicaolog.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolog.''; end if; select count(*) into numrows from convenioshistoricocota where convenioshistoricocota.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenioshistoricocota.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from examerequisicaotrocas where examerequisicaotrocas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaotrocas.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtrocalayout = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codalteracaopreco = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; delete from usuariocompromisso where usuariocompromisso.usr_codigo = old.usr_codigo; select count(*) into numrows from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codsituacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; select count(*) into numrows from contrassenharequisicao where contrassenharequisicao.usr_codgerada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrassenharequisicao.''; end if; select count(*) into numrows from contrassenharequisicao where contrassenharequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrassenharequisicao.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codentrega = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from convenioignorarecebimento where convenioignorarecebimento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenioignorarecebimento.''; end if; select count(*) into numrows from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; select count(*) into numrows from examerequisicaosetor where examerequisicaosetor.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosetor.''; end if; select count(*) into numrows from paciente where paciente.usr_codimpressaocarteira = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; select count(*) into numrows from materialenviado where materialenviado.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialenviado.''; end if; select count(*) into numrows from materialidentificado where materialidentificado.usr_codretorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialidentificado.''; end if; select count(*) into numrows from materialidentificado where materialidentificado.usr_codenvio = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialidentificado.''; end if; select count(*) into numrows from loteapoio where loteapoio.usr_codrecebeucaixa = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteapoio.''; end if; select count(*) into numrows from examerequisicaosoroteca where examerequisicaosoroteca.usr_coddescarte = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosoroteca.''; end if; select count(*) into numrows from examerequisicaosoroteca where examerequisicaosoroteca.usr_codsoroteca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosoroteca.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codguiarepasse = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codrecoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codfaturarepasse = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcomissao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from montagemkit where montagemkit.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela montagemkit.''; end if; select count(*) into numrows from transfestoque where transfestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoque.''; end if; select count(*) into numrows from orcamento where orcamento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamento.''; end if; select count(*) into numrows from estoquemanual where estoquemanual.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela estoquemanual.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codalmoxarife = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codautorizafinanceira = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from conferenciaestoque where conferenciaestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codconciliacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from conferenciaentrada where conferenciaentrada.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaentrada.''; end if; select count(*) into numrows from conferenciaentrada where conferenciaentrada.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaentrada.''; end if; select count(*) into numrows from pedido where pedido.usr_codexclusao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from fatura where fatura.usr_codcomissao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from pedido where pedido.usr_codautorizacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from pedido where pedido.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from cotacao where cotacao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela cotacao.''; end if; select count(*) into numrows from material where material.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela material.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codprotestocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcartoriocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codavisocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codrepeticao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from paciente where paciente.usr_codalteracao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codguia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicaosituacoes where examerequisicaosituacoes.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosituacoes.''; end if; select count(*) into numrows from exames where exames.usr_codassinaweb = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela exames.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codexcluido = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codexcluida = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from fatura where fatura.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from convenios where convenios.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenios.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codreimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from geladeirastemperaturas where geladeirastemperaturas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela geladeirastemperaturas.''; end if; select count(*) into numrows from geladeiras where geladeiras.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela geladeiras.''; end if; delete from usuariofilial where usuariofilial.usr_codigo = old.usr_codigo; select count(*) into numrows from notafiscal where notafiscal.usr_codimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codcancelada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from baixa where baixa.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela baixa.''; end if; select count(*) into numrows from baixa where baixa.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela baixa.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from lanctocaixa where lanctocaixa.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctocaixa.''; end if; select count(*) into numrows from requisicaocid10 where requisicaocid10.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaocid10.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmaterialsetor = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codloteexterno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codenvio = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codcriacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from log where log.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela log.''; end if; select count(*) into numrows from usuariomensagem where usuariomensagem.usr_codorigem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuariomensagem.''; end if; delete from usuariomensagem where usuariomensagem.usr_coddestino = old.usr_codigo; select count(*) into numrows from conveniomensagem where conveniomensagem.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conveniomensagem.''; end if; select count(*) into numrows from examerequisicaorecipiente where examerequisicaorecipiente.usr_codtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaorecipiente.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codetqtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codetqcoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteapoio where loteapoio.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteapoio.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from fatura where fatura.usr_codconferencia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from fatura where fatura.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from contrasenha where contrasenha.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrasenha.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codnaofaturar = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicaousuario where requisicaousuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaousuario.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codabertura = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codcortesia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmapa = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from interfaceexamerequisicao where interfaceexamerequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela interfaceexamerequisicao.''; end if; select count(*) into numrows from usuarioparametro where usuarioparametro.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuarioparametro.''; end if; select count(*) into numrows from lanctocaixa where lanctocaixa.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctocaixa.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codentrega = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codfatura = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmaterial = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_coddigitador = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codassina = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; delete from usuarioacesso where usuarioacesso.usr_codigo = old.usr_codigo; select count(*) into numrows from setores where setores.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setores.''; end if; select count(*) into numrows from paciente where paciente.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; return old; end;' language 'plpgsql'; create trigger td_usuario after delete on usuario for each row execute procedure fn_td_usuario(); drop function fn_ti_usuario() cascade; create function fn_ti_usuario() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from tipousuario where new.tpu_codigo = tipousuario.tpu_codigo; tmp:=''tipousuario|''; tmp:=tmp || ''tpu_codigo='' || new.tpu_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.tpu_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela tipousuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_usuario after insert on usuario for each row execute procedure fn_ti_usuario(); drop function fn_tu_usuario() cascade; create function fn_tu_usuario() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.usr_codigo <> new.usr_codigo) then select count(*) from lotefilialexamerequisicao where lotefilialexamerequisicao.usr_codtransportechegada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilialexamerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lotefilialexamerequisicao where lotefilialexamerequisicao.usr_codtransportesaida = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilialexamerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from historicopoliticaweb where historicopoliticaweb.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela historicopoliticaweb.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from preagendamentoevento where preagendamentoevento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamentoevento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexternologintegracao where labexternologintegracao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternologintegracao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexternoversaotermo where labexternoversaotermo.usr_codaceite = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternoversaotermo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from preagendamento where preagendamento.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from preagendamento where preagendamento.usr_codagendou = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_coddialsist = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from integracaosave where integracaosave.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela integracaosave.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from interfaceexamereagente where interfaceexamereagente.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela interfaceexamereagente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricoentrega where examerequisicaohistoricoentrega.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricoentrega.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaopaginasimpressas where requisicaopaginasimpressas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaopaginasimpressas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from tabelaprecoexamesusuario where tabelaprecoexamesusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela tabelaprecoexamesusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codenvioemail = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialusuario where materialusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logids where logids.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logids.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logvalidalotematerial where logvalidalotematerial.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logvalidalotematerial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from material where material.usr_codavisolote = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela material.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariosenhas where usuariosenhas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariosenhas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pacienteimagens where pacienteimagens.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pacienteimagens.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoimagens where requisicaoimagens.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoimagens.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamentoconvenio where orcamentoconvenio.usr_coddesconto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamentoconvenio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_coddesconto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaoetiquetas where examerequisicaoetiquetas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoetiquetas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codduplaconferencia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexternorequisicao where loteexternorequisicao.usr_codestorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexternorequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codestorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallotehistorico where materiallotehistorico.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallotehistorico.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codaberturainicial = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codfechado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codaberto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from responsavelcertificado where responsavelcertificado.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela responsavelcertificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codelegibilidade = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codsolicitadotiss = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codcoletar = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoquematerial where transfestoquematerial.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoquematerial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoque where transfestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaodadosbrutos where examerequisicaodadosbrutos.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaodadosbrutos.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaoincerteza where examerequisicaoincerteza.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoincerteza.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setoresnaoconformidadeusuario where setoresnaoconformidadeusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setoresnaoconformidadeusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setoresnaoconformidade where setoresnaoconformidade.usr_codresponsavelsetor = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setoresnaoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtransportechegada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtransportesaida = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lotefilial where lotefilial.usr_codrecebeu = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lotefilial where lotefilial.usr_codenviou = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logoffline where logoffline.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logoffline.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariologin where usuariologin.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariologin.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from acoesnaoconformidade where acoesnaoconformidade.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela acoesnaoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamentolog where orcamentolog.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamentolog.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamento where orcamento.usr_codaprovado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codconclusao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codanalise = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codregistro = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexterno where labexterno.usr_codconferir = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from banhomariatemperatura where banhomariatemperatura.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela banhomariatemperatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from banhomaria where banhomaria.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela banhomaria.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from filiais_postocoleta where filiais_postocoleta.usr_codcompras = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiais_postocoleta.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from filiais_postocoleta where filiais_postocoleta.usr_codestoque = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiais_postocoleta.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaolaminas where examerequisicaolaminas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaolaminas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codhorarioanexado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codbloqueado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codremovido = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohash where examerequisicaohash.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohash.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codfinalizado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codemcoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codremarcado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaolog where requisicaolog.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolog.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenioshistoricocota where convenioshistoricocota.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenioshistoricocota.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaotrocas where examerequisicaotrocas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaotrocas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtrocalayout = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codalteracaopreco = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariocompromisso where usuariocompromisso.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariocompromisso.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codsituacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrassenharequisicao where contrassenharequisicao.usr_codgerada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrassenharequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrassenharequisicao where contrassenharequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrassenharequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codentrega = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenioignorarecebimento where convenioignorarecebimento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenioignorarecebimento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosetor where examerequisicaosetor.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosetor.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codimpressaocarteira = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialenviado where materialenviado.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialenviado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialidentificado where materialidentificado.usr_codretorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialidentificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialidentificado where materialidentificado.usr_codenvio = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialidentificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteapoio where loteapoio.usr_codrecebeucaixa = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteapoio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosoroteca where examerequisicaosoroteca.usr_coddescarte = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosoroteca where examerequisicaosoroteca.usr_codsoroteca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codguiarepasse = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codrecoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codfaturarepasse = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcomissao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from montagemkit where montagemkit.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela montagemkit.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoque where transfestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamento where orcamento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from estoquemanual where estoquemanual.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela estoquemanual.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codalmoxarife = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codautorizafinanceira = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaestoque where conferenciaestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codconciliacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaentrada where conferenciaentrada.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaentrada.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaentrada where conferenciaentrada.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaentrada.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codexclusao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codcomissao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codautorizacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from cotacao where cotacao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela cotacao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from material where material.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela material.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codprotestocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcartoriocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codavisocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codrepeticao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codalteracao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codguia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosituacoes where examerequisicaosituacoes.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosituacoes.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from exames where exames.usr_codassinaweb = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exames.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codexcluido = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codexcluida = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenios where convenios.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenios.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codreimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from geladeirastemperaturas where geladeirastemperaturas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela geladeirastemperaturas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from geladeiras where geladeiras.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela geladeiras.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariofilial where usuariofilial.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariofilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codcancelada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from baixa where baixa.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela baixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from baixa where baixa.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela baixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctocaixa where lanctocaixa.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctocaixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaocid10 where requisicaocid10.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaocid10.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmaterialsetor = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codloteexterno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codenvio = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codcriacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from log where log.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela log.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariomensagem where usuariomensagem.usr_codorigem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariomensagem where usuariomensagem.usr_coddestino = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conveniomensagem where conveniomensagem.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conveniomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaorecipiente where examerequisicaorecipiente.usr_codtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaorecipiente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codetqtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codetqcoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteapoio where loteapoio.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteapoio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codconferencia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrasenha where contrasenha.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrasenha.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codnaofaturar = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaousuario where requisicaousuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaousuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codabertura = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codcortesia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmapa = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from interfaceexamerequisicao where interfaceexamerequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela interfaceexamerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuarioparametro where usuarioparametro.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuarioparametro.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctocaixa where lanctocaixa.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctocaixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codentrega = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codfatura = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmaterial = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_coddigitador = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codassina = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuarioacesso where usuarioacesso.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuarioacesso.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setores where setores.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setores.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; select count(*) into numrows from tipousuario where new.tpu_codigo = tipousuario.tpu_codigo; tmp:=''tipousuario|''; tmp:=tmp || ''tpu_codigo='' || new.tpu_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.tpu_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela tipousuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_usuario after update on usuario for each row execute procedure fn_tu_usuario(); insert into atualizacoes(atu_nome) values ('v21020004_230221.sql'); alter table medico add med_bloquearsmsexamepronto boolean default false, add med_bloquearsmsrecoleta boolean default false, add med_bloquearemailexamepronto boolean default false, add med_bloquearemailrecoleta boolean default false; alter table destino add des_bloquearsmsexamepronto boolean default false, add des_bloquearsmsrecoleta boolean default false, add des_bloquearemailexamepronto boolean default false, add des_bloquearemailrecoleta boolean default false; insert into atualizacoes(atu_nome) values ('v21020005_230221.sql'); set session_replication_role=replica; alter table medico add med_inativo boolean default false; set session_replication_role=origin; insert into atualizacoes(atu_nome) values ('v21020006_260221.sql');