insert into atualizacoes(atu_nome) values ('v20060001_230620.sql'); alter table examesdb alter edb_descricaoexame type varchar(180); insert into atualizacoes(atu_nome) values ('v20060002_250620.sql'); alter table filiais_postocoleta add fil_emailagendamento boolean, add fil_smsagendamento boolean, add fil_fraseemailagendamento text, add fil_frasesmsagendamento varchar(3000), add fil_assuntoemailagendamento varchar(100); insert into atualizacoes(atu_nome) values ('v20060003_030720.sql'); alter table examerequisicao add usr_coddialsist varchar(20), add exr_enviadornds timestamp, add exr_datadialsist timestamp; create index xif428examerequisicao on examerequisicao ( usr_coddialsist ); CREATE INDEX XIE12ExameRequisicao ON ExameRequisicao ( fil_codigo, exr_enviadornds ); drop function fn_td_examerequisicao() cascade; create function fn_td_examerequisicao() returns opaque as ' declare numrows integer; begin select count(*) into numrows from integracaosaveexamerequisicao where integracaosaveexamerequisicao.fil_kodigo = old.fil_codigo and integracaosaveexamerequisicao.exa_codigo = old.exa_codigo and integracaosaveexamerequisicao.mco_codigo = old.mco_codigo and integracaosaveexamerequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela integracaosaveexamerequisicao.''; end if; select count(*) into numrows from examerequisicaohistoricoentrega where examerequisicaohistoricoentrega.fil_codigo = old.fil_codigo and examerequisicaohistoricoentrega.exa_codigo = old.exa_codigo and examerequisicaohistoricoentrega.mco_codigo = old.mco_codigo and examerequisicaohistoricoentrega.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricoentrega.''; end if; delete from agendamentoexamerequisicao where agendamentoexamerequisicao.fil_codigo = old.fil_codigo and agendamentoexamerequisicao.exa_codigo = old.exa_codigo and agendamentoexamerequisicao.mco_codigo = old.mco_codigo and agendamentoexamerequisicao.req_codigo = old.req_codigo; delete from exportaintegracaohospital where exportaintegracaohospital.fil_codigo = old.fil_codigo and exportaintegracaohospital.exa_codigo = old.exa_codigo and exportaintegracaohospital.mco_codigo = old.mco_codigo and exportaintegracaohospital.req_codigo = old.req_codigo; select count(*) into numrows from logids where logids.fil_codigo = old.fil_codigo and logids.exa_codigo = old.exa_codigo and logids.mco_codigo = old.mco_codigo and logids.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logids.''; end if; delete from examerequisicaohistoricosetor where examerequisicaohistoricosetor.fil_codigo = old.fil_codigo and examerequisicaohistoricosetor.exa_codigo = old.exa_codigo and examerequisicaohistoricosetor.mco_codigo = old.mco_codigo and examerequisicaohistoricosetor.req_codigo = old.req_codigo; delete from examerequisicaoetiquetas where examerequisicaoetiquetas.fil_codigo = old.fil_codigo and examerequisicaoetiquetas.exa_codigo = old.exa_codigo and examerequisicaoetiquetas.mco_codigo = old.mco_codigo and examerequisicaoetiquetas.req_codigo = old.req_codigo; delete from examerequisicaoemailatraso where examerequisicaoemailatraso.fil_codigo = old.fil_codigo and examerequisicaoemailatraso.exa_codigo = old.exa_codigo and examerequisicaoemailatraso.mco_codigo = old.mco_codigo and examerequisicaoemailatraso.req_codigo = old.req_codigo; select count(*) into numrows from examerequisicaodadosbrutos where examerequisicaodadosbrutos.fil_codigo = old.fil_codigo and examerequisicaodadosbrutos.exa_codigo = old.exa_codigo and examerequisicaodadosbrutos.mco_codigo = old.mco_codigo and examerequisicaodadosbrutos.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaodadosbrutos.''; end if; delete from examerequisicaoincerteza where examerequisicaoincerteza.fil_codigo = old.fil_codigo and examerequisicaoincerteza.exa_codigo = old.exa_codigo and examerequisicaoincerteza.mco_codigo = old.mco_codigo and examerequisicaoincerteza.req_codigo = old.req_codigo; select count(*) into numrows from lotefilialexamerequisicao where lotefilialexamerequisicao.fil_codigo = old.fil_codigo and lotefilialexamerequisicao.exa_codigo = old.exa_codigo and lotefilialexamerequisicao.mco_codigo = old.mco_codigo and lotefilialexamerequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilialexamerequisicao.''; end if; delete from examerequisicaoresultado where examerequisicaoresultado.fil_codigo = old.fil_codigo and examerequisicaoresultado.exa_codigo = old.exa_codigo and examerequisicaoresultado.mco_codigo = old.mco_codigo and examerequisicaoresultado.req_codigo = old.req_codigo; select count(*) into numrows from examerequisicaolaminas where examerequisicaolaminas.fil_codigo = old.fil_codigo and examerequisicaolaminas.exa_codigo = old.exa_codigo and examerequisicaolaminas.mco_codigo = old.mco_codigo and examerequisicaolaminas.req_codigo = old.req_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 examerequisicaohash where examerequisicaohash.fil_codigo = old.fil_codigo and examerequisicaohash.exa_codigo = old.exa_codigo and examerequisicaohash.mco_codigo = old.mco_codigo and examerequisicaohash.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohash.''; end if; delete from examerequisicaotrocas where examerequisicaotrocas.fil_codigo = old.fil_codigo and examerequisicaotrocas.exa_codigo = old.exa_codigo and examerequisicaotrocas.mco_codigo = old.mco_codigo and examerequisicaotrocas.req_codigo = old.req_codigo; delete from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.fil_codigo = old.fil_codigo and examerequisicaohistoricolaudo.exa_codigo = old.exa_codigo and examerequisicaohistoricolaudo.mco_codigo = old.mco_codigo and examerequisicaohistoricolaudo.req_codigo = old.req_codigo; delete from examerequisicaosetor where examerequisicaosetor.fil_codigo = old.fil_codigo and examerequisicaosetor.exa_codigo = old.exa_codigo and examerequisicaosetor.mco_codigo = old.mco_codigo and examerequisicaosetor.req_codigo = old.req_codigo; select count(*) into numrows from examerequisicaoguiaagrupada where examerequisicaoguiaagrupada.fil_codigo = old.fil_codigo and examerequisicaoguiaagrupada.exa_codigo = old.exa_codigo and examerequisicaoguiaagrupada.mco_codigo = old.mco_codigo and examerequisicaoguiaagrupada.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaoguiaagrupada.''; end if; delete from examerequisicaosituacoes where examerequisicaosituacoes.fil_codigo = old.fil_codigo and examerequisicaosituacoes.exa_codigo = old.exa_codigo and examerequisicaosituacoes.mco_codigo = old.mco_codigo and examerequisicaosituacoes.req_codigo = old.req_codigo; select count(*) into numrows from loteexternoexamerequisicao where loteexternoexamerequisicao.fil_kodigo = old.fil_codigo and loteexternoexamerequisicao.exa_codigo = old.exa_codigo and loteexternoexamerequisicao.mco_codigo = old.mco_codigo and loteexternoexamerequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexternoexamerequisicao.''; end if; delete from examerequisicaorecipiente where examerequisicaorecipiente.fil_codigo = old.fil_codigo and examerequisicaorecipiente.exa_codigo = old.exa_codigo and examerequisicaorecipiente.mco_codigo = old.mco_codigo and examerequisicaorecipiente.req_codigo = old.req_codigo; select count(*) into numrows from faturaexamerequisicao where faturaexamerequisicao.fil_kodigo = old.fil_codigo and faturaexamerequisicao.exa_codigo = old.exa_codigo and faturaexamerequisicao.mco_codigo = old.mco_codigo and faturaexamerequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela faturaexamerequisicao.''; end if; delete from interfaceexamerequisicao where interfaceexamerequisicao.fil_codigo = old.fil_codigo and interfaceexamerequisicao.exa_codigo = old.exa_codigo and interfaceexamerequisicao.mco_codigo = old.mco_codigo and interfaceexamerequisicao.req_codigo = old.req_codigo; delete from materialexamerequis where materialexamerequis.fil_codigo = old.fil_codigo and materialexamerequis.exa_codigo = old.exa_codigo and materialexamerequis.mco_codigo = old.mco_codigo and materialexamerequis.req_codigo = old.req_codigo; delete from examerequisicaoresultado where fil_codigo = old.fil_codigo and req_codigo = old.req_codigo and exa_codigo = old.exa_codigo and mco_codigo = old.mco_codigo; return old; end' language 'plpgsql'; create trigger td_examerequisicao after delete on examerequisicao for each row execute procedure fn_td_examerequisicao(); drop function fn_ti_examerequisicao() cascade; create function fn_ti_examerequisicao() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_coddialsist = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_coddialsist || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_coddialsist 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_codenvioemail = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codenvioemail || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codenvioemail 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 motivorecoleta where new.fil_codigo = motivorecoleta.fil_codigo and new.mrc_codigo = motivorecoleta.mrc_codigo; tmp:=''motivorecoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''mrc_codigo='' || new.mrc_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.mrc_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela motivorecoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codduplaconferencia = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codduplaconferencia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codduplaconferencia 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_codsolicitadotiss = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codsolicitadotiss || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codsolicitadotiss 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 examematcoleta where new.fil_codigo = examematcoleta.fil_codigo and new.exa_codigopai = examematcoleta.exa_codigo and new.mco_codigopai = examematcoleta.mco_codigo; tmp:=''examematcoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigopai || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigopai || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.exa_codigopai is not null and new.mco_codigopai is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela examematcoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codcoletar = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcoletar || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcoletar 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_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 usuario where new.usr_codtrocalayout = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtrocalayout || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtrocalayout 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_codalteracaopreco = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codalteracaopreco || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codalteracaopreco 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_codrecoleta = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codrecoleta || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codrecoleta 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_codfaturarepasse = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codfaturarepasse || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codfaturarepasse 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_codrepeticao = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codrepeticao || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codrepeticao 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_codguia = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codguia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codguia 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_codexcluido = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codexcluido || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codexcluido 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_codmaterialsetor = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codmaterialsetor || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codmaterialsetor 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_codloteexterno = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codloteexterno || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codloteexterno 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_codetqtriagem = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codetqtriagem || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codetqtriagem 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_codetqcoleta = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codetqcoleta || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codetqcoleta 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_codtriagem = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtriagem || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtriagem 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_codnaofaturar = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codnaofaturar || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codnaofaturar 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_codcortesia = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcortesia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcortesia 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_codmapa = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codmapa || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codmapa 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_codigo = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codigo 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 examematcoleta where new.fil_codigo = examematcoleta.fil_codigo and new.exa_codigo = examematcoleta.exa_codigo and new.mco_codigo = examematcoleta.mco_codigo; tmp:=''examematcoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_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 examematcoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codimpressao = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codimpressao || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codimpressao 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_codentrega = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codentrega || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codentrega 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_codfatura = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codfatura || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codfatura 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_codmaterial = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codmaterial || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codmaterial 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_coddigitador = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_coddigitador || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_coddigitador 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_codassina = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codassina || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codassina 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 materialcoleta where new.fil_codigo = materialcoleta.fil_codigo and new.mco_codigo = materialcoleta.mco_codigo; tmp:=''materialcoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.mco_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela materialcoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from requisicao where new.fil_codigo = requisicao.fil_codigo and new.req_codigo = requisicao.req_codigo; tmp:=''requisicao|''; tmp:=tmp || ''fil_codigo='' || new.fil_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 requisicao. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; insert into examerequisicaoresultado(fil_codigo, req_codigo, exa_codigo, mco_codigo, ert_resultado) values (new.fil_codigo, new.req_codigo, new.exa_codigo, new.mco_codigo, new.exr_resultado); /* troca o valor do campo de resultado na tabela exame requisicao */ new.exr_resultado = ''.''; return new; end' language 'plpgsql'; create trigger ti_examerequisicao after insert on examerequisicao for each row execute procedure fn_ti_examerequisicao(); drop function fn_tu_b_examerequisicao() cascade; create function fn_tu_b_examerequisicao() returns opaque as ' declare req bigint; begin select req_codigo into req from examerequisicaoresultado where fil_codigo = new.fil_codigo and req_codigo = new.req_codigo and exa_codigo = new.exa_codigo and mco_codigo = new.mco_codigo; if (not found) then insert into examerequisicaoresultado(fil_codigo, req_codigo, exa_codigo, mco_codigo) values (new.fil_codigo, new.req_codigo, new.exa_codigo, new.mco_codigo); end if; if ((upper(new.exr_situacao) = upper(''l'') or upper(new.exr_situacao) = upper(''c'') or upper(new.exr_situacao) = upper(''i'') or upper(new.exr_situacao) = upper(''e'') or upper(new.exr_situacao) = upper(''p'')) and new.exr_resultado is not null and length(new.exr_resultado) > 0) then update examerequisicaoresultado set ert_resultado = new.exr_resultado where fil_codigo = new.fil_codigo and req_codigo = new.req_codigo and exa_codigo = new.exa_codigo and mco_codigo = new.mco_codigo; end if; if ((new.exr_situacao is null or new.exr_situacao = '''' or upper(new.exr_situacao) = upper(''f'') or upper(new.exr_situacao) = upper(''t'') or upper(new.exr_situacao) = upper(''r''))) then update examerequisicaoresultado set ert_resultado = new.exr_resultado where fil_codigo = new.fil_codigo and req_codigo = new.req_codigo and exa_codigo = new.exa_codigo and mco_codigo = new.mco_codigo; end if; /* troca o valor do campo de resultado na tabela exame requisicao */ new.exr_resultado := null; return new; end' language 'plpgsql'; create trigger tu_b_examerequisicao before update on examerequisicao for each row execute procedure fn_tu_b_examerequisicao(); drop function fn_tu_examerequisicao() cascade; create function fn_tu_examerequisicao() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_coddialsist = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_coddialsist || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_coddialsist 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_codenvioemail = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codenvioemail || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codenvioemail 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 motivorecoleta where new.fil_codigo = motivorecoleta.fil_codigo and new.mrc_codigo = motivorecoleta.mrc_codigo; tmp:=''motivorecoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''mrc_codigo='' || new.mrc_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.mrc_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela motivorecoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codduplaconferencia = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codduplaconferencia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codduplaconferencia 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_codsolicitadotiss = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codsolicitadotiss || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codsolicitadotiss 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 examematcoleta where new.fil_codigo = examematcoleta.fil_codigo and new.exa_codigopai = examematcoleta.exa_codigo and new.mco_codigopai = examematcoleta.mco_codigo; tmp:=''examematcoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigopai || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigopai || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.exa_codigopai is not null and new.mco_codigopai is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela examematcoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codcoletar = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcoletar || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcoletar 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_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 usuario where new.usr_codtrocalayout = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtrocalayout || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtrocalayout 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_codalteracaopreco = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codalteracaopreco || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codalteracaopreco 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_codrecoleta = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codrecoleta || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codrecoleta 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_codfaturarepasse = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codfaturarepasse || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codfaturarepasse 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_codrepeticao = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codrepeticao || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codrepeticao 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_codguia = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codguia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codguia 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_codexcluido = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codexcluido || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codexcluido 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_codmaterialsetor = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codmaterialsetor || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codmaterialsetor 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_codloteexterno = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codloteexterno || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codloteexterno 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_codetqtriagem = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codetqtriagem || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codetqtriagem 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_codetqcoleta = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codetqcoleta || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codetqcoleta 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_codtriagem = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codtriagem || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codtriagem 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_codnaofaturar = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codnaofaturar || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codnaofaturar 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_codcortesia = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcortesia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcortesia 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_codmapa = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codmapa || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codmapa 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_codigo = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codigo 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 examematcoleta where new.fil_codigo = examematcoleta.fil_codigo and new.exa_codigo = examematcoleta.exa_codigo and new.mco_codigo = examematcoleta.mco_codigo; tmp:=''examematcoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_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 examematcoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codimpressao = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codimpressao || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codimpressao 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_codentrega = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codentrega || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codentrega 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_codfatura = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codfatura || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codfatura 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_codmaterial = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codmaterial || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codmaterial 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_coddigitador = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_coddigitador || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_coddigitador 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_codassina = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codassina || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codassina 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 materialcoleta where new.fil_codigo = materialcoleta.fil_codigo and new.mco_codigo = materialcoleta.mco_codigo; tmp:=''materialcoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.mco_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela materialcoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from requisicao where new.fil_codigo = requisicao.fil_codigo and new.req_codigo = requisicao.req_codigo; tmp:=''requisicao|''; tmp:=tmp || ''fil_codigo='' || new.fil_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 requisicao. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from integracaosaveexamerequisicao where integracaosaveexamerequisicao.fil_kodigo = old.fil_codigo and integracaosaveexamerequisicao.exa_codigo = old.exa_codigo and integracaosaveexamerequisicao.mco_codigo = old.mco_codigo and integracaosaveexamerequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela integracaosaveexamerequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaohistoricoentrega where examerequisicaohistoricoentrega.fil_codigo = old.fil_codigo and examerequisicaohistoricoentrega.exa_codigo = old.exa_codigo and examerequisicaohistoricoentrega.mco_codigo = old.mco_codigo and examerequisicaohistoricoentrega.req_codigo = old.req_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.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from agendamentoexamerequisicao where agendamentoexamerequisicao.fil_codigo = old.fil_codigo and agendamentoexamerequisicao.exa_codigo = old.exa_codigo and agendamentoexamerequisicao.mco_codigo = old.mco_codigo and agendamentoexamerequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamentoexamerequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from exportaintegracaohospital where exportaintegracaohospital.fil_codigo = old.fil_codigo and exportaintegracaohospital.exa_codigo = old.exa_codigo and exportaintegracaohospital.mco_codigo = old.mco_codigo and exportaintegracaohospital.req_codigo = old.req_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 or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from logids where logids.fil_codigo = old.fil_codigo and logids.exa_codigo = old.exa_codigo and logids.mco_codigo = old.mco_codigo and logids.req_codigo = old.req_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.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaohistoricosetor where examerequisicaohistoricosetor.fil_codigo = old.fil_codigo and examerequisicaohistoricosetor.exa_codigo = old.exa_codigo and examerequisicaohistoricosetor.mco_codigo = old.mco_codigo and examerequisicaohistoricosetor.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricosetor.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaoetiquetas where examerequisicaoetiquetas.fil_codigo = old.fil_codigo and examerequisicaoetiquetas.exa_codigo = old.exa_codigo and examerequisicaoetiquetas.mco_codigo = old.mco_codigo and examerequisicaoetiquetas.req_codigo = old.req_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.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaoemailatraso where examerequisicaoemailatraso.fil_codigo = old.fil_codigo and examerequisicaoemailatraso.exa_codigo = old.exa_codigo and examerequisicaoemailatraso.mco_codigo = old.mco_codigo and examerequisicaoemailatraso.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoemailatraso.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaodadosbrutos where examerequisicaodadosbrutos.fil_codigo = old.fil_codigo and examerequisicaodadosbrutos.exa_codigo = old.exa_codigo and examerequisicaodadosbrutos.mco_codigo = old.mco_codigo and examerequisicaodadosbrutos.req_codigo = old.req_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.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaoincerteza where examerequisicaoincerteza.fil_codigo = old.fil_codigo and examerequisicaoincerteza.exa_codigo = old.exa_codigo and examerequisicaoincerteza.mco_codigo = old.mco_codigo and examerequisicaoincerteza.req_codigo = old.req_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.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from lotefilialexamerequisicao where lotefilialexamerequisicao.fil_codigo = old.fil_codigo and lotefilialexamerequisicao.exa_codigo = old.exa_codigo and lotefilialexamerequisicao.mco_codigo = old.mco_codigo and lotefilialexamerequisicao.req_codigo = old.req_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.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaoresultado where examerequisicaoresultado.fil_codigo = old.fil_codigo and examerequisicaoresultado.exa_codigo = old.exa_codigo and examerequisicaoresultado.mco_codigo = old.mco_codigo and examerequisicaoresultado.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoresultado.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaolaminas where examerequisicaolaminas.fil_codigo = old.fil_codigo and examerequisicaolaminas.exa_codigo = old.exa_codigo and examerequisicaolaminas.mco_codigo = old.mco_codigo and examerequisicaolaminas.req_codigo = old.req_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.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaohash where examerequisicaohash.fil_codigo = old.fil_codigo and examerequisicaohash.exa_codigo = old.exa_codigo and examerequisicaohash.mco_codigo = old.mco_codigo and examerequisicaohash.req_codigo = old.req_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 or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaotrocas where examerequisicaotrocas.fil_codigo = old.fil_codigo and examerequisicaotrocas.exa_codigo = old.exa_codigo and examerequisicaotrocas.mco_codigo = old.mco_codigo and examerequisicaotrocas.req_codigo = old.req_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.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.fil_codigo = old.fil_codigo and examerequisicaohistoricolaudo.exa_codigo = old.exa_codigo and examerequisicaohistoricolaudo.mco_codigo = old.mco_codigo and examerequisicaohistoricolaudo.req_codigo = old.req_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 or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaosetor where examerequisicaosetor.fil_codigo = old.fil_codigo and examerequisicaosetor.exa_codigo = old.exa_codigo and examerequisicaosetor.mco_codigo = old.mco_codigo and examerequisicaosetor.req_codigo = old.req_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 or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaoguiaagrupada where examerequisicaoguiaagrupada.fil_codigo = old.fil_codigo and examerequisicaoguiaagrupada.exa_codigo = old.exa_codigo and examerequisicaoguiaagrupada.mco_codigo = old.mco_codigo and examerequisicaoguiaagrupada.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoguiaagrupada.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaosituacoes where examerequisicaosituacoes.fil_codigo = old.fil_codigo and examerequisicaosituacoes.exa_codigo = old.exa_codigo and examerequisicaosituacoes.mco_codigo = old.mco_codigo and examerequisicaosituacoes.req_codigo = old.req_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.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from loteexternoexamerequisicao where loteexternoexamerequisicao.fil_kodigo = old.fil_codigo and loteexternoexamerequisicao.exa_codigo = old.exa_codigo and loteexternoexamerequisicao.mco_codigo = old.mco_codigo and loteexternoexamerequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexternoexamerequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicaorecipiente where examerequisicaorecipiente.fil_codigo = old.fil_codigo and examerequisicaorecipiente.exa_codigo = old.exa_codigo and examerequisicaorecipiente.mco_codigo = old.mco_codigo and examerequisicaorecipiente.req_codigo = old.req_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.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from faturaexamerequisicao where faturaexamerequisicao.fil_kodigo = old.fil_codigo and faturaexamerequisicao.exa_codigo = old.exa_codigo and faturaexamerequisicao.mco_codigo = old.mco_codigo and faturaexamerequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela faturaexamerequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from interfaceexamerequisicao where interfaceexamerequisicao.fil_codigo = old.fil_codigo and interfaceexamerequisicao.exa_codigo = old.exa_codigo and interfaceexamerequisicao.mco_codigo = old.mco_codigo and interfaceexamerequisicao.req_codigo = old.req_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.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.mco_codigo <> new.mco_codigo or old.req_codigo <> new.req_codigo) then select count(*) from materialexamerequis where materialexamerequis.fil_codigo = old.fil_codigo and materialexamerequis.exa_codigo = old.exa_codigo and materialexamerequis.mco_codigo = old.mco_codigo and materialexamerequis.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialexamerequis.''; end if; end if; return new; end' language 'plpgsql'; create trigger tu_examerequisicao after update on examerequisicao for each row execute procedure fn_tu_examerequisicao(); drop function fn_td_usuario() cascade; create function fn_td_usuario() returns opaque as ' declare numrows integer; begin 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 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 ('v20060004_030820.sql'); create table examelayoutmetodornds ( rnd_codigo serial not null, fil_codigo integer, exa_codigo varchar(5), lay_codigo integer, mco_codigo integer, ela_idadeini integer, ela_idadefim integer, ela_idadeinitipo varchar(1), ela_idadefimtipo varchar(1), met_codigo integer, rnd_versao integer, rnd_campo varchar(200), rnd_loinc varchar(7), rnd_expressao text, rnd_interpretacao text, rnd_formato text ); create unique index xpkexamelayoutmetodornds on examelayoutmetodornds ( rnd_codigo ); create unique index xak1examelayoutmetodornds on examelayoutmetodornds ( fil_codigo, exa_codigo, lay_codigo, mco_codigo, ela_idadeini, ela_idadefim, ela_idadeinitipo, ela_idadefimtipo, met_codigo, rnd_versao, rnd_campo ); create index xif1examelayoutmetodornds on examelayoutmetodornds ( fil_codigo, exa_codigo, lay_codigo, mco_codigo, ela_idadeini, ela_idadefim, ela_idadeinitipo, ela_idadefimtipo, met_codigo ); alter table examelayoutmetodornds add primary key (rnd_codigo); drop function fn_td_examelayoutmetodo() cascade; create function fn_td_examelayoutmetodo() returns opaque as ' declare numrows integer; begin delete from examelayoutmetodornds where examelayoutmetodornds.fil_codigo = old.fil_codigo and examelayoutmetodornds.exa_codigo = old.exa_codigo and examelayoutmetodornds.lay_codigo = old.lay_codigo and examelayoutmetodornds.mco_codigo = old.mco_codigo and examelayoutmetodornds.ela_idadeini = old.ela_idadeini and examelayoutmetodornds.ela_idadefim = old.ela_idadefim and examelayoutmetodornds.ela_idadeinitipo = old.ela_idadeinitipo and examelayoutmetodornds.ela_idadefimtipo = old.ela_idadefimtipo and examelayoutmetodornds.met_codigo = old.met_codigo; delete from examelayoutmetodoincerteza where examelayoutmetodoincerteza.fil_codigo = old.fil_codigo and examelayoutmetodoincerteza.exa_codigo = old.exa_codigo and examelayoutmetodoincerteza.lay_codigo = old.lay_codigo and examelayoutmetodoincerteza.mco_codigo = old.mco_codigo and examelayoutmetodoincerteza.ela_idadeini = old.ela_idadeini and examelayoutmetodoincerteza.ela_idadefim = old.ela_idadefim and examelayoutmetodoincerteza.ela_idadeinitipo = old.ela_idadeinitipo and examelayoutmetodoincerteza.ela_idadefimtipo = old.ela_idadefimtipo and examelayoutmetodoincerteza.met_codigo = old.met_codigo; return old; end;' language 'plpgsql'; create trigger td_examelayoutmetodo after delete on examelayoutmetodo for each row execute procedure fn_td_examelayoutmetodo(); drop function fn_ti_examelayoutmetodo() cascade; create function fn_ti_examelayoutmetodo() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_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 metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from examelayout where new.fil_codigo = examelayout.fil_codigo and new.exa_codigo = examelayout.exa_codigo and new.lay_codigo = examelayout.lay_codigo and new.mco_codigo = examelayout.mco_codigo and new.ela_idadeini = examelayout.ela_idadeini and new.ela_idadefim = examelayout.ela_idadefim and new.ela_idadeinitipo = examelayout.ela_idadeinitipo and new.ela_idadefimtipo = examelayout.ela_idadefimtipo; tmp:=''examelayout|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigo || ''|''; tmp:=tmp || ''lay_codigo='' || new.lay_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=tmp || ''ela_idadeini='' || new.ela_idadeini || ''|''; tmp:=tmp || ''ela_idadefim='' || new.ela_idadefim || ''|''; tmp:=tmp || ''ela_idadeinitipo='' || new.ela_idadeinitipo || ''|''; tmp:=tmp || ''ela_idadefimtipo='' || new.ela_idadefimtipo || ''|''; 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 examelayout. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_examelayoutmetodo after insert on examelayoutmetodo for each row execute procedure fn_ti_examelayoutmetodo(); drop function fn_tu_examelayoutmetodo() cascade; create function fn_tu_examelayoutmetodo() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.lay_codigo <> new.lay_codigo or old.mco_codigo <> new.mco_codigo or old.ela_idadeini <> new.ela_idadeini or old.ela_idadefim <> new.ela_idadefim or old.ela_idadeinitipo <> new.ela_idadeinitipo or old.ela_idadefimtipo <> new.ela_idadefimtipo or old.met_codigo <> new.met_codigo) then select count(*) from examelayoutmetodornds where examelayoutmetodornds.fil_codigo = old.fil_codigo and examelayoutmetodornds.exa_codigo = old.exa_codigo and examelayoutmetodornds.lay_codigo = old.lay_codigo and examelayoutmetodornds.mco_codigo = old.mco_codigo and examelayoutmetodornds.ela_idadeini = old.ela_idadeini and examelayoutmetodornds.ela_idadefim = old.ela_idadefim and examelayoutmetodornds.ela_idadeinitipo = old.ela_idadeinitipo and examelayoutmetodornds.ela_idadefimtipo = old.ela_idadefimtipo and examelayoutmetodornds.met_codigo = old.met_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examelayoutmetodornds.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.lay_codigo <> new.lay_codigo or old.mco_codigo <> new.mco_codigo or old.ela_idadeini <> new.ela_idadeini or old.ela_idadefim <> new.ela_idadefim or old.ela_idadeinitipo <> new.ela_idadeinitipo or old.ela_idadefimtipo <> new.ela_idadefimtipo or old.met_codigo <> new.met_codigo) then select count(*) from examelayoutmetodoincerteza where examelayoutmetodoincerteza.fil_codigo = old.fil_codigo and examelayoutmetodoincerteza.exa_codigo = old.exa_codigo and examelayoutmetodoincerteza.lay_codigo = old.lay_codigo and examelayoutmetodoincerteza.mco_codigo = old.mco_codigo and examelayoutmetodoincerteza.ela_idadeini = old.ela_idadeini and examelayoutmetodoincerteza.ela_idadefim = old.ela_idadefim and examelayoutmetodoincerteza.ela_idadeinitipo = old.ela_idadeinitipo and examelayoutmetodoincerteza.ela_idadefimtipo = old.ela_idadefimtipo and examelayoutmetodoincerteza.met_codigo = old.met_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examelayoutmetodoincerteza.''; end if; end if; select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_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 metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from examelayout where new.fil_codigo = examelayout.fil_codigo and new.exa_codigo = examelayout.exa_codigo and new.lay_codigo = examelayout.lay_codigo and new.mco_codigo = examelayout.mco_codigo and new.ela_idadeini = examelayout.ela_idadeini and new.ela_idadefim = examelayout.ela_idadefim and new.ela_idadeinitipo = examelayout.ela_idadeinitipo and new.ela_idadefimtipo = examelayout.ela_idadefimtipo; tmp:=''examelayout|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigo || ''|''; tmp:=tmp || ''lay_codigo='' || new.lay_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=tmp || ''ela_idadeini='' || new.ela_idadeini || ''|''; tmp:=tmp || ''ela_idadefim='' || new.ela_idadefim || ''|''; tmp:=tmp || ''ela_idadeinitipo='' || new.ela_idadeinitipo || ''|''; tmp:=tmp || ''ela_idadefimtipo='' || new.ela_idadefimtipo || ''|''; 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 examelayout. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_examelayoutmetodo after update on examelayoutmetodo for each row execute procedure fn_tu_examelayoutmetodo(); --drop function fn_ti_examelayoutmetodornds() cascade; create function fn_ti_examelayoutmetodornds() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from examelayoutmetodo where new.fil_codigo = examelayoutmetodo.fil_codigo and new.exa_codigo = examelayoutmetodo.exa_codigo and new.lay_codigo = examelayoutmetodo.lay_codigo and new.mco_codigo = examelayoutmetodo.mco_codigo and new.ela_idadeini = examelayoutmetodo.ela_idadeini and new.ela_idadefim = examelayoutmetodo.ela_idadefim and new.ela_idadeinitipo = examelayoutmetodo.ela_idadeinitipo and new.ela_idadefimtipo = examelayoutmetodo.ela_idadefimtipo and new.met_codigo = examelayoutmetodo.met_codigo; tmp:=''examelayoutmetodo|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigo || ''|''; tmp:=tmp || ''lay_codigo='' || new.lay_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=tmp || ''ela_idadeini='' || new.ela_idadeini || ''|''; tmp:=tmp || ''ela_idadefim='' || new.ela_idadefim || ''|''; tmp:=tmp || ''ela_idadeinitipo='' || new.ela_idadeinitipo || ''|''; tmp:=tmp || ''ela_idadefimtipo='' || new.ela_idadefimtipo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.exa_codigo is not null and new.lay_codigo is not null and new.mco_codigo is not null and new.ela_idadeini is not null and new.ela_idadefim is not null and new.ela_idadeinitipo is not null and new.ela_idadefimtipo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela examelayoutmetodo. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_examelayoutmetodornds after insert on examelayoutmetodornds for each row execute procedure fn_ti_examelayoutmetodornds(); --drop function fn_tu_examelayoutmetodornds() cascade; create function fn_tu_examelayoutmetodornds() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from examelayoutmetodo where new.fil_codigo = examelayoutmetodo.fil_codigo and new.exa_codigo = examelayoutmetodo.exa_codigo and new.lay_codigo = examelayoutmetodo.lay_codigo and new.mco_codigo = examelayoutmetodo.mco_codigo and new.ela_idadeini = examelayoutmetodo.ela_idadeini and new.ela_idadefim = examelayoutmetodo.ela_idadefim and new.ela_idadeinitipo = examelayoutmetodo.ela_idadeinitipo and new.ela_idadefimtipo = examelayoutmetodo.ela_idadefimtipo and new.met_codigo = examelayoutmetodo.met_codigo; tmp:=''examelayoutmetodo|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigo || ''|''; tmp:=tmp || ''lay_codigo='' || new.lay_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=tmp || ''ela_idadeini='' || new.ela_idadeini || ''|''; tmp:=tmp || ''ela_idadefim='' || new.ela_idadefim || ''|''; tmp:=tmp || ''ela_idadeinitipo='' || new.ela_idadeinitipo || ''|''; tmp:=tmp || ''ela_idadefimtipo='' || new.ela_idadefimtipo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.exa_codigo is not null and new.lay_codigo is not null and new.mco_codigo is not null and new.ela_idadeini is not null and new.ela_idadefim is not null and new.ela_idadeinitipo is not null and new.ela_idadefimtipo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela examelayoutmetodo. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_examelayoutmetodornds after update on examelayoutmetodornds for each row execute procedure fn_tu_examelayoutmetodornds(); select configurageralog('examelayoutmetodornds'); insert into atualizacoes(atu_nome) values ('v20060005_030820.sql'); drop function fn_td_examelayoutmetodo() cascade; create function fn_td_examelayoutmetodo() returns opaque as ' declare numrows integer; begin delete from examelayoutmetodoincerteza where examelayoutmetodoincerteza.fil_codigo = old.fil_codigo and examelayoutmetodoincerteza.exa_codigo = old.exa_codigo and examelayoutmetodoincerteza.lay_codigo = old.lay_codigo and examelayoutmetodoincerteza.mco_codigo = old.mco_codigo and examelayoutmetodoincerteza.ela_idadeini = old.ela_idadeini and examelayoutmetodoincerteza.ela_idadefim = old.ela_idadefim and examelayoutmetodoincerteza.ela_idadeinitipo = old.ela_idadeinitipo and examelayoutmetodoincerteza.ela_idadefimtipo = old.ela_idadefimtipo and examelayoutmetodoincerteza.met_codigo = old.met_codigo; return old; end;' language 'plpgsql'; create trigger td_examelayoutmetodo after delete on examelayoutmetodo for each row execute procedure fn_td_examelayoutmetodo(); drop function fn_ti_examelayoutmetodo() cascade; create function fn_ti_examelayoutmetodo() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_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 metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from examelayout where new.fil_codigo = examelayout.fil_codigo and new.exa_codigo = examelayout.exa_codigo and new.lay_codigo = examelayout.lay_codigo and new.mco_codigo = examelayout.mco_codigo and new.ela_idadeini = examelayout.ela_idadeini and new.ela_idadefim = examelayout.ela_idadefim and new.ela_idadeinitipo = examelayout.ela_idadeinitipo and new.ela_idadefimtipo = examelayout.ela_idadefimtipo; tmp:=''examelayout|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigo || ''|''; tmp:=tmp || ''lay_codigo='' || new.lay_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=tmp || ''ela_idadeini='' || new.ela_idadeini || ''|''; tmp:=tmp || ''ela_idadefim='' || new.ela_idadefim || ''|''; tmp:=tmp || ''ela_idadeinitipo='' || new.ela_idadeinitipo || ''|''; tmp:=tmp || ''ela_idadefimtipo='' || new.ela_idadefimtipo || ''|''; 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 examelayout. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_examelayoutmetodo after insert on examelayoutmetodo for each row execute procedure fn_ti_examelayoutmetodo(); drop function fn_tu_examelayoutmetodo() cascade; create function fn_tu_examelayoutmetodo() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo or old.lay_codigo <> new.lay_codigo or old.mco_codigo <> new.mco_codigo or old.ela_idadeini <> new.ela_idadeini or old.ela_idadefim <> new.ela_idadefim or old.ela_idadeinitipo <> new.ela_idadeinitipo or old.ela_idadefimtipo <> new.ela_idadefimtipo or old.met_codigo <> new.met_codigo) then select count(*) from examelayoutmetodoincerteza where examelayoutmetodoincerteza.fil_codigo = old.fil_codigo and examelayoutmetodoincerteza.exa_codigo = old.exa_codigo and examelayoutmetodoincerteza.lay_codigo = old.lay_codigo and examelayoutmetodoincerteza.mco_codigo = old.mco_codigo and examelayoutmetodoincerteza.ela_idadeini = old.ela_idadeini and examelayoutmetodoincerteza.ela_idadefim = old.ela_idadefim and examelayoutmetodoincerteza.ela_idadeinitipo = old.ela_idadeinitipo and examelayoutmetodoincerteza.ela_idadefimtipo = old.ela_idadefimtipo and examelayoutmetodoincerteza.met_codigo = old.met_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examelayoutmetodoincerteza.''; end if; end if; select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_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 metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from examelayout where new.fil_codigo = examelayout.fil_codigo and new.exa_codigo = examelayout.exa_codigo and new.lay_codigo = examelayout.lay_codigo and new.mco_codigo = examelayout.mco_codigo and new.ela_idadeini = examelayout.ela_idadeini and new.ela_idadefim = examelayout.ela_idadefim and new.ela_idadeinitipo = examelayout.ela_idadeinitipo and new.ela_idadefimtipo = examelayout.ela_idadefimtipo; tmp:=''examelayout|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigo || ''|''; tmp:=tmp || ''lay_codigo='' || new.lay_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=tmp || ''ela_idadeini='' || new.ela_idadeini || ''|''; tmp:=tmp || ''ela_idadefim='' || new.ela_idadefim || ''|''; tmp:=tmp || ''ela_idadeinitipo='' || new.ela_idadeinitipo || ''|''; tmp:=tmp || ''ela_idadefimtipo='' || new.ela_idadefimtipo || ''|''; 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 examelayout. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_examelayoutmetodo after update on examelayoutmetodo for each row execute procedure fn_tu_examelayoutmetodo(); drop function fn_ti_examelayoutmetodornds() cascade; create function fn_ti_examelayoutmetodornds() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from examelayoutmetodo where new.fil_codigo = examelayoutmetodo.fil_codigo and new.exa_codigo = examelayoutmetodo.exa_codigo and new.lay_codigo = examelayoutmetodo.lay_codigo and new.mco_codigo = examelayoutmetodo.mco_codigo and new.ela_idadeini = examelayoutmetodo.ela_idadeini and new.ela_idadefim = examelayoutmetodo.ela_idadefim and new.ela_idadeinitipo = examelayoutmetodo.ela_idadeinitipo and new.ela_idadefimtipo = examelayoutmetodo.ela_idadefimtipo and new.met_codigo = examelayoutmetodo.met_codigo; tmp:=''examelayoutmetodo|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigo || ''|''; tmp:=tmp || ''lay_codigo='' || new.lay_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=tmp || ''ela_idadeini='' || new.ela_idadeini || ''|''; tmp:=tmp || ''ela_idadefim='' || new.ela_idadefim || ''|''; tmp:=tmp || ''ela_idadeinitipo='' || new.ela_idadeinitipo || ''|''; tmp:=tmp || ''ela_idadefimtipo='' || new.ela_idadefimtipo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.exa_codigo is not null and new.lay_codigo is not null and new.mco_codigo is not null and new.ela_idadeini is not null and new.ela_idadefim is not null and new.ela_idadeinitipo is not null and new.ela_idadefimtipo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela examelayoutmetodo. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_examelayoutmetodornds after insert on examelayoutmetodornds for each row execute procedure fn_ti_examelayoutmetodornds(); drop function fn_tu_examelayoutmetodornds() cascade; create function fn_tu_examelayoutmetodornds() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from examelayoutmetodo where new.fil_codigo = examelayoutmetodo.fil_codigo and new.exa_codigo = examelayoutmetodo.exa_codigo and new.lay_codigo = examelayoutmetodo.lay_codigo and new.mco_codigo = examelayoutmetodo.mco_codigo and new.ela_idadeini = examelayoutmetodo.ela_idadeini and new.ela_idadefim = examelayoutmetodo.ela_idadefim and new.ela_idadeinitipo = examelayoutmetodo.ela_idadeinitipo and new.ela_idadefimtipo = examelayoutmetodo.ela_idadefimtipo and new.met_codigo = examelayoutmetodo.met_codigo; tmp:=''examelayoutmetodo|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_codigo || ''|''; tmp:=tmp || ''lay_codigo='' || new.lay_codigo || ''|''; tmp:=tmp || ''mco_codigo='' || new.mco_codigo || ''|''; tmp:=tmp || ''ela_idadeini='' || new.ela_idadeini || ''|''; tmp:=tmp || ''ela_idadefim='' || new.ela_idadefim || ''|''; tmp:=tmp || ''ela_idadeinitipo='' || new.ela_idadeinitipo || ''|''; tmp:=tmp || ''ela_idadefimtipo='' || new.ela_idadefimtipo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.exa_codigo is not null and new.lay_codigo is not null and new.mco_codigo is not null and new.ela_idadeini is not null and new.ela_idadefim is not null and new.ela_idadeinitipo is not null and new.ela_idadefimtipo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela examelayoutmetodo. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_examelayoutmetodornds after update on examelayoutmetodornds for each row execute procedure fn_tu_examelayoutmetodornds(); insert into atualizacoes(atu_nome) values ('v20060006_060820.sql'); alter table examelayoutmetodornds add rnd_sus varchar(4), add rnd_material varchar(10); create table loincrnds ( loi_codigo varchar(7) not null, loi_descricao varchar(200) ); create unique index xpkloincrnds on loincrnds ( loi_codigo ); alter table loincrnds add primary key (loi_codigo); create table materialrnds ( mrd_codigo varchar(10) not null, mrd_descricao varchar(200) ); create unique index xpkmaterialrnds on materialrnds ( mrd_codigo ); alter table materialrnds add primary key (mrd_codigo); create table susrnds ( sus_codigo varchar(4) not null, sus_descricao varchar(200) ); create unique index xpksusrnds on susrnds ( sus_codigo ); alter table susrnds add primary key (sus_codigo); select configurageralog('loincrnds'); select configurageralog('materialrnds'); select configurageralog('susrnds'); insert into atualizacoes(atu_nome) values ('v20060007_100820.sql'); alter table configuracaoweb add cwe_permitiragendamento boolean default false, add cwe_xmlagendamento text; create table preagendamento ( fil_codigo integer not null, pre_codigo integer not null, pre_datahora timestamp default current_timestamp, pre_codigopaciente integer, pre_nomepaciente varchar(100), pre_enderecopaciente varchar(100), pre_numeroenderecopaciente varchar(30), pre_bairropaciente varchar(100), pre_cidadepaciente varchar(100), pre_estadopaciente varchar(2), pre_fonepaciente varchar(20), pre_celularpaciente varchar(20), pre_sexopaciente varchar(1), pre_situacao varchar(1), pre_dataprevista date, pre_horarioprevisto varchar(50), pre_unidadeselecionada varchar(100), pre_convenio varchar(100), pre_medico varchar(100), pre_convenionaoinformado boolean default false, pre_mediconaoinformado boolean default false, pre_descritivoexames varchar(2000), pre_motivosituacao varchar(200), pre_datahoraagendou timestamp, pre_codigofilialpaciente integer, pre_alterardadospaciente boolean default false, pre_tipoexamesinformados varchar(1), pre_datacancelamento timestamp, usr_codagendou varchar(20), usr_codcancelamento varchar(20) ); create unique index xpkpreagendamento on preagendamento ( fil_codigo, pre_codigo ); create index xif1preagendamento on preagendamento ( fil_codigo ); create index xif2preagendamento on preagendamento ( usr_codagendou ); create index xif3preagendamento on preagendamento ( usr_codcancelamento ); alter table preagendamento add primary key (fil_codigo, pre_codigo); create table preagendamentoexame ( fil_codigo integer not null, pre_codigo integer not null, exa_codigo varchar(5) not null ); create unique index xpkpreagendamentoexame on preagendamentoexame ( fil_codigo, pre_codigo, exa_codigo ); create index xif1preagendamentoexame on preagendamentoexame ( fil_codigo, pre_codigo ); create index xif2preagendamentoexame on preagendamentoexame ( fil_codigo, exa_codigo ); alter table preagendamentoexame add primary key (fil_codigo, pre_codigo, exa_codigo); create table preagendamentoimagem ( fil_codigo integer not null, pre_codigo integer not null, pig_codigo serial not null, pig_tipo varchar(1), pig_imagem text ); create unique index xpkpreagendamentoimagem on preagendamentoimagem ( fil_codigo, pre_codigo, pig_codigo ); create index xif1preagendamentoimagem on preagendamentoimagem ( fil_codigo, pre_codigo ); alter table preagendamentoimagem add primary key (fil_codigo, pre_codigo, pig_codigo); drop function fn_td_exames() cascade; create function fn_td_exames() returns opaque as ' declare numrows integer; begin select count(*) into numrows from preagendamentoexame where preagendamentoexame.fil_codigo = old.fil_codigo and preagendamentoexame.exa_codigo = old.exa_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamentoexame.''; end if; select count(*) into numrows from tagsresultadoanterior where tagsresultadoanterior.fil_codigo = old.fil_codigo and tagsresultadoanterior.exa_codigo = old.exa_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela tagsresultadoanterior.''; end if; delete from examecoletadestino where examecoletadestino.fil_codigo = old.fil_codigo and examecoletadestino.exa_codigo = old.exa_codigo; select count(*) into numrows from medicoexameweb where medicoexameweb.fil_codigo = old.fil_codigo and medicoexameweb.exa_codigo = old.exa_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela medicoexameweb.''; end if; select count(*) into numrows from filiaisexamesexportar where filiaisexamesexportar.fil_codigo = old.fil_codigo and filiaisexamesexportar.exa_codigo = old.exa_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiaisexamesexportar.''; end if; delete from examesetor where examesetor.fil_codigo = old.fil_codigo and examesetor.exa_codigo = old.exa_codigo; delete from examematcoleta where examematcoleta.fil_codigo = old.fil_codigo and examematcoleta.exa_codigo = old.exa_codigo; delete from examehistorico where examehistorico.fil_codigo = old.fil_codigo and examehistorico.exa_codigo = old.exa_codigo; return old; end;' language 'plpgsql'; create trigger td_exames after delete on exames for each row execute procedure fn_td_exames(); drop function fn_ti_exames() cascade; create function fn_ti_exames() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_codassinaweb = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codassinaweb || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codassinaweb 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_exames after insert on exames for each row execute procedure fn_ti_exames(); drop function fn_tu_exames() cascade; create function fn_tu_exames() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo) then select count(*) from preagendamentoexame where preagendamentoexame.fil_codigo = old.fil_codigo and preagendamentoexame.exa_codigo = old.exa_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamentoexame.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo) then select count(*) from tagsresultadoanterior where tagsresultadoanterior.fil_codigo = old.fil_codigo and tagsresultadoanterior.exa_codigo = old.exa_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela tagsresultadoanterior.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo) then select count(*) from examecoletadestino where examecoletadestino.fil_codigo = old.fil_codigo and examecoletadestino.exa_codigo = old.exa_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examecoletadestino.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo) then select count(*) from medicoexameweb where medicoexameweb.fil_codigo = old.fil_codigo and medicoexameweb.exa_codigo = old.exa_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela medicoexameweb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo) then select count(*) from filiaisexamesexportar where filiaisexamesexportar.fil_codigo = old.fil_codigo and filiaisexamesexportar.exa_codigo = old.exa_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 or old.exa_codigo <> new.exa_codigo) then select count(*) from examesetor where examesetor.fil_codigo = old.fil_codigo and examesetor.exa_codigo = old.exa_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesetor.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo) then select count(*) from examematcoleta where examematcoleta.fil_codigo = old.fil_codigo and examematcoleta.exa_codigo = old.exa_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examematcoleta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.exa_codigo <> new.exa_codigo) then select count(*) from examehistorico where examehistorico.fil_codigo = old.fil_codigo and examehistorico.exa_codigo = old.exa_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examehistorico.''; end if; end if; select count(*) into numrows from usuario where new.usr_codassinaweb = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codassinaweb || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codassinaweb 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_exames after update on exames for each row execute procedure fn_tu_exames(); 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 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 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_preagendamento() cascade; create function fn_td_preagendamento() returns opaque as ' declare numrows integer; begin delete from preagendamentoimagem where preagendamentoimagem.fil_codigo = old.fil_codigo and preagendamentoimagem.pre_codigo = old.pre_codigo; delete from preagendamentoexame where preagendamentoexame.fil_codigo = old.fil_codigo and preagendamentoexame.pre_codigo = old.pre_codigo; return old; end;' language 'plpgsql'; create trigger td_preagendamento after delete on preagendamento for each row execute procedure fn_td_preagendamento(); --drop function fn_ti_preagendamento() cascade; create function fn_ti_preagendamento() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_codcancelamento = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcancelamento || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcancelamento 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_codagendou = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codagendou || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codagendou 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_preagendamento after insert on preagendamento for each row execute procedure fn_ti_preagendamento(); --drop function fn_tu_preagendamento() cascade; create function fn_tu_preagendamento() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.pre_codigo <> new.pre_codigo) then select count(*) from preagendamentoimagem where preagendamentoimagem.fil_codigo = old.fil_codigo and preagendamentoimagem.pre_codigo = old.pre_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamentoimagem.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.pre_codigo <> new.pre_codigo) then select count(*) from preagendamentoexame where preagendamentoexame.fil_codigo = old.fil_codigo and preagendamentoexame.pre_codigo = old.pre_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamentoexame.''; end if; end if; select count(*) into numrows from usuario where new.usr_codcancelamento = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcancelamento || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcancelamento 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_codagendou = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codagendou || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codagendou 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_preagendamento after update on preagendamento for each row execute procedure fn_tu_preagendamento(); --drop function fn_ti_preagendamentoexame() cascade; create function fn_ti_preagendamentoexame() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from exames where new.fil_codigo = exames.fil_codigo and new.exa_codigo = exames.exa_codigo; tmp:=''exames|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_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 exames. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from preagendamento where new.fil_codigo = preagendamento.fil_codigo and new.pre_codigo = preagendamento.pre_codigo; tmp:=''preagendamento|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pre_codigo='' || new.pre_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 preagendamento. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_preagendamentoexame after insert on preagendamentoexame for each row execute procedure fn_ti_preagendamentoexame(); --drop function fn_tu_preagendamentoexame() cascade; create function fn_tu_preagendamentoexame() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from exames where new.fil_codigo = exames.fil_codigo and new.exa_codigo = exames.exa_codigo; tmp:=''exames|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''exa_codigo='' || new.exa_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 exames. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from preagendamento where new.fil_codigo = preagendamento.fil_codigo and new.pre_codigo = preagendamento.pre_codigo; tmp:=''preagendamento|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pre_codigo='' || new.pre_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 preagendamento. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_preagendamentoexame after update on preagendamentoexame for each row execute procedure fn_tu_preagendamentoexame(); --drop function fn_ti_preagendamentoimagem() cascade; create function fn_ti_preagendamentoimagem() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from preagendamento where new.fil_codigo = preagendamento.fil_codigo and new.pre_codigo = preagendamento.pre_codigo; tmp:=''preagendamento|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pre_codigo='' || new.pre_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 preagendamento. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_preagendamentoimagem after insert on preagendamentoimagem for each row execute procedure fn_ti_preagendamentoimagem(); --drop function fn_tu_preagendamentoimagem() cascade; create function fn_tu_preagendamentoimagem() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from preagendamento where new.fil_codigo = preagendamento.fil_codigo and new.pre_codigo = preagendamento.pre_codigo; tmp:=''preagendamento|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pre_codigo='' || new.pre_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 preagendamento. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_preagendamentoimagem after update on preagendamentoimagem for each row execute procedure fn_tu_preagendamentoimagem(); drop function fn_td_usuario() cascade; create function fn_td_usuario() returns opaque as ' declare numrows integer; begin 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 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(); select configurageralog('preagendamento'); select configurageralog('preagendamentoimagem'); select configurageralog('preagendamentoexame'); select criasequencia('preagendamento'); insert into atualizacoes(atu_nome) values ('v20060008_200820.sql');