create sequence guiaorizon_sequence; select criasequencia('guiaorizon'); alter table convenios alter con_norma type varchar(8000); insert into atualizacoes(atu_nome) values ('v17090001_281117.sql'); set session_replication_role=replica; alter table loteexterno alter lex_codigo type bigint; alter table loteexternorequisicao alter lex_codigo type bigint; alter table loteexternoexamerequisicao alter lex_codigo type bigint; alter table loteexternoexamerequisicaodesm alter lex_codigo type bigint; alter table loteexternoexamerequisicaorecip alter lex_codigo type bigint; set session_replication_role=replica; alter table loteexterno alter lex_codigo type bigint; alter table loteexternorequisicao alter lex_codigo type bigint; alter table loteexternoexamerequisicao alter lex_codigo type bigint; alter table loteexternoexamerequisicaodesm alter lex_codigo type bigint; alter table loteexternoexamerequisicaorecip alter lex_codigo type bigint; create function criasequenciaslote() returns integer as $$ declare r record; begin for r in select fil_codigo, lae_codigo from labexterno order by 1,2 loop execute 'create sequence codigolote_' || r.fil_codigo || '_' || r.lae_codigo || '_sequence;'; end loop; return 1; end$$ language 'plpgsql'; select criasequenciaslote(); drop function criasequenciaslote(); insert into atualizacoes(atu_nome) values ('v17090002_011217.sql'); alter table estacoes add est_tamanhointegracao integer; insert into atualizacoes(atu_nome) values ('v17090003_011217.sql'); set session_replication_role=replica; alter table usuariomensagem add ume_tipo varchar(1) default 'C'; alter table material add mat_diasavisolote integer, add usr_codavisolote varchar(20); alter table material add mat_avisarvalidadelote boolean; create index xif225material on material ( usr_codavisolote ); drop function fn_td_material() cascade; create function fn_td_material() returns opaque as ' declare numrows integer; begin select count(*) into numrows from materialalternativo where materialalternativo.fil_codigo = old.fil_codigo and materialalternativo.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialalternativo.''; end if; select count(*) into numrows from materiallote where materiallote.fil_codigo = old.fil_codigo and materiallote.mat_codigo = old.mat_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 materialenviadomaterial where materialenviadomaterial.fil_codigo = old.fil_codigo and materialenviadomaterial.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialenviadomaterial.''; end if; select count(*) into numrows from materialidentificado where materialidentificado.fil_codigo = old.fil_codigo and materialidentificado.mat_codigo = old.mat_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 montagemkitconsumido where montagemkitconsumido.fil_codigo = old.fil_codigo and montagemkitconsumido.mat_codconsumido = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela montagemkitconsumido.''; end if; select count(*) into numrows from montagemkitmaterial where montagemkitmaterial.fil_codigo = old.fil_codigo and montagemkitmaterial.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela montagemkitmaterial.''; end if; select count(*) into numrows from transfestoquematerial where transfestoquematerial.fil_codigo = old.fil_codigo and transfestoquematerial.mat_codigo = old.mat_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 estoquemanualmaterial where estoquemanualmaterial.fil_codigo = old.fil_codigo and estoquemanualmaterial.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela estoquemanualmaterial.''; end if; select count(*) into numrows from requisicaoestoquematerial where requisicaoestoquematerial.fil_codigo = old.fil_codigo and requisicaoestoquematerial.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoquematerial.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.fil_codigo = old.fil_codigo and lanctoestoque.mat_codigo = old.mat_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 conferenciaestoquematerial where conferenciaestoquematerial.fil_codigo = old.fil_codigo and conferenciaestoquematerial.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaestoquematerial.''; end if; select count(*) into numrows from conferenciaentradamaterial where conferenciaentradamaterial.fil_codigo = old.fil_codigo and conferenciaentradamaterial.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaentradamaterial.''; end if; select count(*) into numrows from notafiscalmaterial where notafiscalmaterial.fil_codigo = old.fil_codigo and notafiscalmaterial.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscalmaterial.''; end if; select count(*) into numrows from pedidomaterial where pedidomaterial.fil_codigo = old.fil_codigo and pedidomaterial.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedidomaterial.''; end if; select count(*) into numrows from fichatecnicamaterial where fichatecnicamaterial.fil_codigo = old.fil_codigo and fichatecnicamaterial.mat_codigofilho = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fichatecnicamaterial.''; end if; select count(*) into numrows from fichatecnicamaterial where fichatecnicamaterial.fil_codigo = old.fil_codigo and fichatecnicamaterial.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fichatecnicamaterial.''; end if; select count(*) into numrows from cotacaomaterial where cotacaomaterial.fil_codigo = old.fil_codigo and cotacaomaterial.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela cotacaomaterial.''; end if; select count(*) into numrows from saldoestoquecelula where saldoestoquecelula.fil_codigo = old.fil_codigo and saldoestoquecelula.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela saldoestoquecelula.''; end if; select count(*) into numrows from saldoestoque where saldoestoque.fil_codigo = old.fil_codigo and saldoestoque.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela saldoestoque.''; end if; select count(*) into numrows from materialpatrimonio where materialpatrimonio.fil_codigo = old.fil_codigo and materialpatrimonio.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialpatrimonio.''; end if; select count(*) into numrows from recipmaterial where recipmaterial.fil_codigo = old.fil_codigo and recipmaterial.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela recipmaterial.''; end if; select count(*) into numrows from materialexamerequis where materialexamerequis.fil_codigo = old.fil_codigo and materialexamerequis.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialexamerequis.''; end if; select count(*) into numrows from materialexame where materialexame.fil_codigo = old.fil_codigo and materialexame.mat_codigo = old.mat_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialexame.''; end if; return old; end;' language 'plpgsql'; create trigger td_material after delete on material for each row execute procedure fn_td_material(); drop function fn_ti_material() cascade; create function fn_ti_material() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_codavisolote = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codavisolote || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codavisolote 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 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; select count(*) into numrows from unidademedida where new.fil_codigo = unidademedida.fil_codigo and new.unm_codigo = unidademedida.unm_codigo; tmp:=''unidademedida|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''unm_codigo='' || new.unm_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.unm_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela unidademedida. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from tipomaterial where new.fil_codigo = tipomaterial.fil_codigo and new.tpm_codigo = tipomaterial.tpm_codigo; tmp:=''tipomaterial|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''tpm_codigo='' || new.tpm_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.tpm_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela tipomaterial. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_material after insert on material for each row execute procedure fn_ti_material(); drop function fn_tu_material() cascade; create function fn_tu_material() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from materialalternativo where materialalternativo.fil_codigo = old.fil_codigo and materialalternativo.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialalternativo.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from materiallote where materiallote.fil_codigo = old.fil_codigo and materiallote.mat_codigo = old.mat_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 or old.mat_codigo <> new.mat_codigo) then select count(*) from materialenviadomaterial where materialenviadomaterial.fil_codigo = old.fil_codigo and materialenviadomaterial.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialenviadomaterial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from materialidentificado where materialidentificado.fil_codigo = old.fil_codigo and materialidentificado.mat_codigo = old.mat_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.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from montagemkitconsumido where montagemkitconsumido.fil_codigo = old.fil_codigo and montagemkitconsumido.mat_codconsumido = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela montagemkitconsumido.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from montagemkitmaterial where montagemkitmaterial.fil_codigo = old.fil_codigo and montagemkitmaterial.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela montagemkitmaterial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from transfestoquematerial where transfestoquematerial.fil_codigo = old.fil_codigo and transfestoquematerial.mat_codigo = old.mat_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.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from estoquemanualmaterial where estoquemanualmaterial.fil_codigo = old.fil_codigo and estoquemanualmaterial.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela estoquemanualmaterial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from requisicaoestoquematerial where requisicaoestoquematerial.fil_codigo = old.fil_codigo and requisicaoestoquematerial.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoquematerial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from lanctoestoque where lanctoestoque.fil_codigo = old.fil_codigo and lanctoestoque.mat_codigo = old.mat_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 or old.mat_codigo <> new.mat_codigo) then select count(*) from conferenciaestoquematerial where conferenciaestoquematerial.fil_codigo = old.fil_codigo and conferenciaestoquematerial.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaestoquematerial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from conferenciaentradamaterial where conferenciaentradamaterial.fil_codigo = old.fil_codigo and conferenciaentradamaterial.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaentradamaterial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from notafiscalmaterial where notafiscalmaterial.fil_codigo = old.fil_codigo and notafiscalmaterial.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscalmaterial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from pedidomaterial where pedidomaterial.fil_codigo = old.fil_codigo and pedidomaterial.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedidomaterial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from fichatecnicamaterial where fichatecnicamaterial.fil_codigo = old.fil_codigo and fichatecnicamaterial.mat_codigofilho = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fichatecnicamaterial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from fichatecnicamaterial where fichatecnicamaterial.fil_codigo = old.fil_codigo and fichatecnicamaterial.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fichatecnicamaterial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from cotacaomaterial where cotacaomaterial.fil_codigo = old.fil_codigo and cotacaomaterial.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela cotacaomaterial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from saldoestoquecelula where saldoestoquecelula.fil_codigo = old.fil_codigo and saldoestoquecelula.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela saldoestoquecelula.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from saldoestoque where saldoestoque.fil_codigo = old.fil_codigo and saldoestoque.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela saldoestoque.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from materialpatrimonio where materialpatrimonio.fil_codigo = old.fil_codigo and materialpatrimonio.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialpatrimonio.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from recipmaterial where recipmaterial.fil_codigo = old.fil_codigo and recipmaterial.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela recipmaterial.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from materialexamerequis where materialexamerequis.fil_codigo = old.fil_codigo and materialexamerequis.mat_codigo = old.mat_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; if (old.fil_codigo <> new.fil_codigo or old.mat_codigo <> new.mat_codigo) then select count(*) from materialexame where materialexame.fil_codigo = old.fil_codigo and materialexame.mat_codigo = old.mat_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialexame.''; end if; end if; select count(*) into numrows from usuario where new.usr_codavisolote = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codavisolote || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codavisolote 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 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; select count(*) into numrows from unidademedida where new.fil_codigo = unidademedida.fil_codigo and new.unm_codigo = unidademedida.unm_codigo; tmp:=''unidademedida|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''unm_codigo='' || new.unm_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.unm_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela unidademedida. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from tipomaterial where new.fil_codigo = tipomaterial.fil_codigo and new.tpm_codigo = tipomaterial.tpm_codigo; tmp:=''tipomaterial|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''tpm_codigo='' || new.tpm_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.tpm_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela tipomaterial. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_material after update on material for each row execute procedure fn_tu_material(); drop function fn_td_usuario() cascade; create function fn_td_usuario() returns opaque as ' declare numrows integer; begin 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 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 ('v17090004_051217.sql'); create table logvalidalote ( lvl_codigo serial not null, lvl_datahora timestamp, fil_codigo integer ); create unique index xpklogvalidalote on logvalidalote ( lvl_codigo ); create index xif1logvalidalote on logvalidalote ( fil_codigo ); alter table logvalidalote add primary key (lvl_codigo); create table logvalidalotematerial ( lvl_codigo serial not null, fil_codigo integer, mll_codigo integer, usr_codigo varchar(20) ); create unique index xpklogvalidalotematerial on logvalidalotematerial ( lvl_codigo ); create index xif2logvalidalotematerial on logvalidalotematerial ( fil_codigo, mll_codigo ); create index xif3logvalidalotematerial on logvalidalotematerial ( usr_codigo ); alter table logvalidalotematerial add primary key (lvl_codigo); drop function fn_td_filiais_postocoleta() cascade; create function fn_td_filiais_postocoleta() returns opaque as ' declare numrows integer; begin 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 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_logvalidalote() cascade; create function fn_td_logvalidalote() returns opaque as ' declare numrows integer; begin delete from logvalidalotematerial where logvalidalotematerial.lvl_codigo = old.lvl_codigo; return old; end;' language 'plpgsql'; create trigger td_logvalidalote after delete on logvalidalote for each row execute procedure fn_td_logvalidalote(); --drop function fn_ti_logvalidalote() cascade; create function fn_ti_logvalidalote() returns opaque as ' declare numrows integer; tmp varchar; begin 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 ( new.fil_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_logvalidalote after insert on logvalidalote for each row execute procedure fn_ti_logvalidalote(); --drop function fn_tu_logvalidalote() cascade; create function fn_tu_logvalidalote() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.lvl_codigo <> new.lvl_codigo) then select count(*) from logvalidalotematerial where logvalidalotematerial.lvl_codigo = old.lvl_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; 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 ( new.fil_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_logvalidalote after update on logvalidalote for each row execute procedure fn_tu_logvalidalote(); --drop function fn_ti_logvalidalotematerial() cascade; create function fn_ti_logvalidalotematerial() returns opaque as ' declare numrows integer; tmp varchar; begin 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 materiallote where new.fil_codigo = materiallote.fil_codigo and new.mll_codigo = materiallote.mll_codigo; tmp:=''materiallote|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''mll_codigo='' || new.mll_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.mll_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela materiallote. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from logvalidalote where new.lvl_codigo = logvalidalote.lvl_codigo; tmp:=''logvalidalote|''; tmp:=tmp || ''lvl_codigo='' || new.lvl_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 logvalidalote. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_logvalidalotematerial after insert on logvalidalotematerial for each row execute procedure fn_ti_logvalidalotematerial(); --drop function fn_tu_logvalidalotematerial() cascade; create function fn_tu_logvalidalotematerial() returns opaque as ' declare numrows integer; tmp varchar; begin 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 materiallote where new.fil_codigo = materiallote.fil_codigo and new.mll_codigo = materiallote.mll_codigo; tmp:=''materiallote|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''mll_codigo='' || new.mll_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.mll_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela materiallote. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from logvalidalote where new.lvl_codigo = logvalidalote.lvl_codigo; tmp:=''logvalidalote|''; tmp:=tmp || ''lvl_codigo='' || new.lvl_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 logvalidalote. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_logvalidalotematerial after update on logvalidalotematerial for each row execute procedure fn_tu_logvalidalotematerial(); drop function fn_td_materiallote() cascade; create function fn_td_materiallote() returns opaque as ' declare numrows integer; begin delete from logvalidalotematerial where logvalidalotematerial.fil_codigo = old.fil_codigo and logvalidalotematerial.mll_codigo = old.mll_codigo; select count(*) into numrows from materiallotehistorico where materiallotehistorico.fil_codigo = old.fil_codigo and materiallotehistorico.mll_codigo = old.mll_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 materiallotelanctoestoque where materiallotelanctoestoque.fil_codigo = old.fil_codigo and materiallotelanctoestoque.mll_codigo = old.mll_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallotelanctoestoque.''; end if; select count(*) into numrows from naoconformidadelote where naoconformidadelote.fil_codigo = old.fil_codigo and naoconformidadelote.mll_codigo = old.mll_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidadelote.''; end if; return old; end;' language 'plpgsql'; create trigger td_materiallote after delete on materiallote for each row execute procedure fn_td_materiallote(); drop function fn_ti_materiallote() cascade; create function fn_ti_materiallote() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_codaberturainicial = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codaberturainicial || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codaberturainicial 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_codfechado = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codfechado || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codfechado 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_codaberto = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codaberto || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codaberto 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 lanctoestoque where new.fil_codigo = lanctoestoque.fil_codigo and new.lce_codigo = lanctoestoque.lce_codigo; tmp:=''lanctoestoque|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''lce_codigo='' || new.lce_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.lce_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela lanctoestoque. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codremovido = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codremovido || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codremovido 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 material where new.fil_codigo = material.fil_codigo and new.mat_codigo = material.mat_codigo; tmp:=''material|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''mat_codigo='' || new.mat_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.mat_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela material. 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_materiallote after insert on materiallote for each row execute procedure fn_ti_materiallote(); drop function fn_tu_materiallote() cascade; create function fn_tu_materiallote() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.mll_codigo <> new.mll_codigo) then select count(*) from logvalidalotematerial where logvalidalotematerial.fil_codigo = old.fil_codigo and logvalidalotematerial.mll_codigo = old.mll_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.fil_codigo <> new.fil_codigo or old.mll_codigo <> new.mll_codigo) then select count(*) from materiallotehistorico where materiallotehistorico.fil_codigo = old.fil_codigo and materiallotehistorico.mll_codigo = old.mll_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.fil_codigo <> new.fil_codigo or old.mll_codigo <> new.mll_codigo) then select count(*) from materiallotelanctoestoque where materiallotelanctoestoque.fil_codigo = old.fil_codigo and materiallotelanctoestoque.mll_codigo = old.mll_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallotelanctoestoque.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.mll_codigo <> new.mll_codigo) then select count(*) from naoconformidadelote where naoconformidadelote.fil_codigo = old.fil_codigo and naoconformidadelote.mll_codigo = old.mll_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidadelote.''; end if; end if; select count(*) into numrows from usuario where new.usr_codaberturainicial = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codaberturainicial || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codaberturainicial 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_codfechado = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codfechado || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codfechado 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_codaberto = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codaberto || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codaberto 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 lanctoestoque where new.fil_codigo = lanctoestoque.fil_codigo and new.lce_codigo = lanctoestoque.lce_codigo; tmp:=''lanctoestoque|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''lce_codigo='' || new.lce_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.lce_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela lanctoestoque. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codremovido = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codremovido || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codremovido 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 material where new.fil_codigo = material.fil_codigo and new.mat_codigo = material.mat_codigo; tmp:=''material|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''mat_codigo='' || new.mat_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.mat_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela material. 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_materiallote after update on materiallote for each row execute procedure fn_tu_materiallote(); drop function fn_td_usuario() cascade; create function fn_td_usuario() returns opaque as ' declare numrows integer; begin 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 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 ('v17090005_081217.sql'); alter table examerequisicao add exr_intervalojejum interval; insert into atualizacoes(atu_nome) values ('v17090006_081217.sql');