create table labexternologintegracao ( fil_codigo integer not null, lae_codigo integer not null, lil_codigo serial not null, lil_datahorainicio timestamp, lil_datahorafim timestamp, lil_sucesso boolean default true, lil_tipooperacao varchar(1), lil_envio text, lil_retorno text, usr_codigo varchar(20) ); create unique index xpklabexternologintegracao on labexternologintegracao ( fil_codigo, lae_codigo, lil_codigo ); create index xif1labexternologintegracao on labexternologintegracao ( fil_codigo, lae_codigo ); create index xif2labexternologintegracao on labexternologintegracao ( usr_codigo ); alter table labexternologintegracao add primary key (fil_codigo, lae_codigo, lil_codigo); create table labexternoversaotermo ( fil_codigo integer not null, lae_codigo integer not null, lat_versao varchar(10) not null, lat_datahoraatualizacao timestamp, lat_termo text, lat_datahoraaceite timestamp, usr_codaceite varchar(20) ); create unique index xpklabexternoversaotermo on labexternoversaotermo ( fil_codigo, lae_codigo, lat_versao ); create index xif1labexternoversaotermo on labexternoversaotermo ( fil_codigo, lae_codigo ); create index xif2labexternoversaotermo on labexternoversaotermo ( usr_codaceite ); alter table labexternoversaotermo add primary key (fil_codigo, lae_codigo, lat_versao); drop function fn_td_labexterno() cascade; create function fn_td_labexterno() returns opaque as ' declare numrows integer; begin delete from labexternologintegracao where labexternologintegracao.fil_codigo = old.fil_codigo and labexternologintegracao.lae_codigo = old.lae_codigo; delete from labexternoversaotermo where labexternoversaotermo.fil_codigo = old.fil_codigo and labexternoversaotermo.lae_codigo = old.lae_codigo; select count(*) into numrows from examessaomarcos where examessaomarcos.fil_codigo = old.fil_codigo and examessaomarcos.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examessaomarcos.''; end if; delete from examessyslab where examessyslab.fil_codigo = old.fil_codigo and examessyslab.lae_codigo = old.lae_codigo; delete from examesunilab where examesunilab.fil_codigo = old.fil_codigo and examesunilab.lae_codigo = old.lae_codigo; select count(*) into numrows from filiais_postocoleta where filiais_postocoleta.fil_codigo = old.fil_codigo and filiais_postocoleta.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiais_postocoleta.''; end if; delete from logimportacaolabexterno where logimportacaolabexterno.fil_codigo = old.fil_codigo and logimportacaolabexterno.lae_codigo = old.lae_codigo; select count(*) into numrows from examessolucao where examessolucao.fil_codigo = old.fil_codigo and examessolucao.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examessolucao.''; end if; select count(*) into numrows from examesdb where examesdb.fil_codigo = old.fil_codigo and examesdb.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesdb.''; end if; delete from examesatitude where examesatitude.fil_codigo = old.fil_codigo and examesatitude.lae_codigo = old.lae_codigo; delete from examesbalague where examesbalague.fil_codigo = old.fil_codigo and examesbalague.lae_codigo = old.lae_codigo; delete from examesdelta where examesdelta.fil_codigo = old.fil_codigo and examesdelta.lae_codigo = old.lae_codigo; select count(*) into numrows from examematcoletalabexterno where examematcoletalabexterno.fil_codigo = old.fil_codigo and examematcoletalabexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examematcoletalabexterno.''; end if; select count(*) into numrows from examesmatrix where examesmatrix.fil_codigo = old.fil_codigo and examesmatrix.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesmatrix.''; end if; select count(*) into numrows from examesrede where examesrede.fil_codigo = old.fil_codigo and examesrede.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesrede.''; end if; delete from examesreacao where examesreacao.fil_codigo = old.fil_codigo and examesreacao.lae_codigo = old.lae_codigo; select count(*) into numrows from pacientelabexterno where pacientelabexterno.fil_codigo = old.fil_codigo and pacientelabexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pacientelabexterno.''; end if; select count(*) into numrows from requisicaolabexterno where requisicaolabexterno.fil_codigo = old.fil_codigo and requisicaolabexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolabexterno.''; end if; delete from examessergiofranco where examessergiofranco.fil_codigo = old.fil_codigo and examessergiofranco.lae_codigo = old.lae_codigo; delete from examesalvaro where examesalvaro.fil_codigo = old.fil_codigo and examesalvaro.lae_codigo = old.lae_codigo; select count(*) into numrows from examesjalis where examesjalis.fil_codigo = old.fil_codigo and examesjalis.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesjalis.''; end if; delete from examespardini where examespardini.fil_codigo = old.fil_codigo and examespardini.lae_codigo = old.lae_codigo; select count(*) into numrows from loteexterno where loteexterno.fil_codigo = old.fil_codigo and loteexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; return old; end;' language 'plpgsql'; create trigger td_labexterno after delete on labexterno for each row execute procedure fn_td_labexterno(); drop function fn_ti_labexterno() cascade; create function fn_ti_labexterno() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from prazoentrega where new.fil_codigo = prazoentrega.fil_codigo and new.prz_codigo = prazoentrega.prz_codigo; tmp:=''prazoentrega|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''prz_codigo='' || new.prz_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.prz_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela prazoentrega. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from setores where new.fil_codigo = setores.fil_codigo and new.set_codigo = setores.set_codigo; tmp:=''setores|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''set_codigo='' || new.set_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.set_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela setores. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codconferir = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codconferir || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codconferir is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_labexterno after insert on labexterno for each row execute procedure fn_ti_labexterno(); drop function fn_tu_labexterno() cascade; create function fn_tu_labexterno() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from labexternologintegracao where labexternologintegracao.fil_codigo = old.fil_codigo and labexternologintegracao.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternologintegracao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from labexternoversaotermo where labexternoversaotermo.fil_codigo = old.fil_codigo and labexternoversaotermo.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternoversaotermo.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessaomarcos where examessaomarcos.fil_codigo = old.fil_codigo and examessaomarcos.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessaomarcos.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessyslab where examessyslab.fil_codigo = old.fil_codigo and examessyslab.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessyslab.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesunilab where examesunilab.fil_codigo = old.fil_codigo and examesunilab.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesunilab.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from filiais_postocoleta where filiais_postocoleta.fil_codigo = old.fil_codigo and filiais_postocoleta.lae_codigo = old.lae_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.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from logimportacaolabexterno where logimportacaolabexterno.fil_codigo = old.fil_codigo and logimportacaolabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logimportacaolabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessolucao where examessolucao.fil_codigo = old.fil_codigo and examessolucao.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessolucao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesdb where examesdb.fil_codigo = old.fil_codigo and examesdb.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesdb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesatitude where examesatitude.fil_codigo = old.fil_codigo and examesatitude.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesatitude.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesbalague where examesbalague.fil_codigo = old.fil_codigo and examesbalague.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesbalague.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesdelta where examesdelta.fil_codigo = old.fil_codigo and examesdelta.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesdelta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examematcoletalabexterno where examematcoletalabexterno.fil_codigo = old.fil_codigo and examematcoletalabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examematcoletalabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesmatrix where examesmatrix.fil_codigo = old.fil_codigo and examesmatrix.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesmatrix.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesrede where examesrede.fil_codigo = old.fil_codigo and examesrede.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesrede.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesreacao where examesreacao.fil_codigo = old.fil_codigo and examesreacao.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesreacao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from pacientelabexterno where pacientelabexterno.fil_codigo = old.fil_codigo and pacientelabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pacientelabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from requisicaolabexterno where requisicaolabexterno.fil_codigo = old.fil_codigo and requisicaolabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessergiofranco where examessergiofranco.fil_codigo = old.fil_codigo and examessergiofranco.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessergiofranco.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesalvaro where examesalvaro.fil_codigo = old.fil_codigo and examesalvaro.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesalvaro.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesjalis where examesjalis.fil_codigo = old.fil_codigo and examesjalis.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesjalis.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examespardini where examespardini.fil_codigo = old.fil_codigo and examespardini.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examespardini.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from loteexterno where loteexterno.fil_codigo = old.fil_codigo and loteexterno.lae_codigo = old.lae_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; select count(*) into numrows from prazoentrega where new.fil_codigo = prazoentrega.fil_codigo and new.prz_codigo = prazoentrega.prz_codigo; tmp:=''prazoentrega|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''prz_codigo='' || new.prz_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.prz_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela prazoentrega. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from setores where new.fil_codigo = setores.fil_codigo and new.set_codigo = setores.set_codigo; tmp:=''setores|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''set_codigo='' || new.set_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.set_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela setores. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codconferir = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codconferir || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codconferir is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_labexterno after update on labexterno for each row execute procedure fn_tu_labexterno(); --drop function fn_ti_labexternologintegracao() cascade; create function fn_ti_labexternologintegracao() 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 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 ( 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; return new; end;' language 'plpgsql'; create trigger ti_labexternologintegracao after insert on labexternologintegracao for each row execute procedure fn_ti_labexternologintegracao(); --drop function fn_tu_labexternologintegracao() cascade; create function fn_tu_labexternologintegracao() 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 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 ( 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; return old; end;' language 'plpgsql'; create trigger tu_labexternologintegracao after update on labexternologintegracao for each row execute procedure fn_tu_labexternologintegracao(); --drop function fn_ti_labexternoversaotermo() cascade; create function fn_ti_labexternoversaotermo() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_codaceite = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codaceite || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codaceite 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 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 ( 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; return new; end;' language 'plpgsql'; create trigger ti_labexternoversaotermo after insert on labexternoversaotermo for each row execute procedure fn_ti_labexternoversaotermo(); --drop function fn_tu_labexternoversaotermo() cascade; create function fn_tu_labexternoversaotermo() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_codaceite = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codaceite || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codaceite 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 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 ( 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; return old; end;' language 'plpgsql'; create trigger tu_labexternoversaotermo after update on labexternoversaotermo for each row execute procedure fn_tu_labexternoversaotermo(); drop function fn_td_usuario() cascade; create function fn_td_usuario() returns opaque as ' declare numrows integer; begin select count(*) into numrows from labexternologintegracao where labexternologintegracao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexternologintegracao.''; end if; select count(*) into numrows from labexternoversaotermo where labexternoversaotermo.usr_codaceite = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexternoversaotermo.''; end if; select count(*) into numrows from preagendamento where preagendamento.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamento.''; end if; select count(*) into numrows from preagendamento where preagendamento.usr_codagendou = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamento.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_coddialsist = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from integracaosave where integracaosave.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela integracaosave.''; end if; select count(*) into numrows from interfaceexamereagente where interfaceexamereagente.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela interfaceexamereagente.''; end if; select count(*) into numrows from examerequisicaohistoricoentrega where examerequisicaohistoricoentrega.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricoentrega.''; end if; select count(*) into numrows from requisicaopaginasimpressas where requisicaopaginasimpressas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaopaginasimpressas.''; end if; select count(*) into numrows from tabelaprecoexamesusuario where tabelaprecoexamesusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela tabelaprecoexamesusuario.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codenvioemail = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from materialusuario where materialusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialusuario.''; end if; select count(*) into numrows from logids where logids.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logids.''; end if; select count(*) into numrows from logvalidalotematerial where logvalidalotematerial.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logvalidalotematerial.''; end if; select count(*) into numrows from material where material.usr_codavisolote = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela material.''; end if; delete from usuariosenhas where usuariosenhas.usr_codigo = old.usr_codigo; select count(*) into numrows from pacienteimagens where pacienteimagens.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pacienteimagens.''; end if; select count(*) into numrows from requisicaoimagens where requisicaoimagens.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoimagens.''; end if; select count(*) into numrows from orcamentoconvenio where orcamentoconvenio.usr_coddesconto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamentoconvenio.''; end if; select count(*) into numrows from requisicao where requisicao.usr_coddesconto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicaoetiquetas where examerequisicaoetiquetas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaoetiquetas.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codduplaconferencia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteexternorequisicao where loteexternorequisicao.usr_codestorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexternorequisicao.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codestorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from materiallotehistorico where materiallotehistorico.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallotehistorico.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codaberturainicial = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codfechado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codaberto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; delete from responsavelcertificado where responsavelcertificado.usr_codigo = old.usr_codigo; select count(*) into numrows from requisicao where requisicao.usr_codelegibilidade = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codsolicitadotiss = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codcoletar = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from transfestoquematerial where transfestoquematerial.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoquematerial.''; end if; select count(*) into numrows from transfestoque where transfestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoque.''; end if; select count(*) into numrows from examerequisicaodadosbrutos where examerequisicaodadosbrutos.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaodadosbrutos.''; end if; select count(*) into numrows from examerequisicaoincerteza where examerequisicaoincerteza.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaoincerteza.''; end if; select count(*) into numrows from setoresnaoconformidadeusuario where setoresnaoconformidadeusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setoresnaoconformidadeusuario.''; end if; select count(*) into numrows from setoresnaoconformidade where setoresnaoconformidade.usr_codresponsavelsetor = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setoresnaoconformidade.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtransportechegada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtransportesaida = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from lotefilial where lotefilial.usr_codrecebeu = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilial.''; end if; select count(*) into numrows from lotefilial where lotefilial.usr_codenviou = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilial.''; end if; select count(*) into numrows from logoffline where logoffline.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logoffline.''; end if; select count(*) into numrows from usuariologin where usuariologin.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuariologin.''; end if; select count(*) into numrows from acoesnaoconformidade where acoesnaoconformidade.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela acoesnaoconformidade.''; end if; select count(*) into numrows from orcamentolog where orcamentolog.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamentolog.''; end if; select count(*) into numrows from orcamento where orcamento.usr_codaprovado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamento.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codconclusao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codanalise = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codregistro = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from labexterno where labexterno.usr_codconferir = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexterno.''; end if; select count(*) into numrows from banhomariatemperatura where banhomariatemperatura.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela banhomariatemperatura.''; end if; select count(*) into numrows from banhomaria where banhomaria.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela banhomaria.''; end if; select count(*) into numrows from filiais_postocoleta where filiais_postocoleta.usr_codcompras = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiais_postocoleta.''; end if; select count(*) into numrows from filiais_postocoleta where filiais_postocoleta.usr_codestoque = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiais_postocoleta.''; end if; select count(*) into numrows from examerequisicaolaminas where examerequisicaolaminas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaolaminas.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codhorarioanexado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codbloqueado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codremovido = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from examerequisicaohash where examerequisicaohash.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohash.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codfinalizado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codemcoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codremarcado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from requisicaolog where requisicaolog.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolog.''; end if; select count(*) into numrows from convenioshistoricocota where convenioshistoricocota.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenioshistoricocota.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from examerequisicaotrocas where examerequisicaotrocas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaotrocas.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtrocalayout = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codalteracaopreco = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; delete from usuariocompromisso where usuariocompromisso.usr_codigo = old.usr_codigo; select count(*) into numrows from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codsituacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; select count(*) into numrows from contrassenharequisicao where contrassenharequisicao.usr_codgerada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrassenharequisicao.''; end if; select count(*) into numrows from contrassenharequisicao where contrassenharequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrassenharequisicao.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codentrega = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from convenioignorarecebimento where convenioignorarecebimento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenioignorarecebimento.''; end if; select count(*) into numrows from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; select count(*) into numrows from examerequisicaosetor where examerequisicaosetor.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosetor.''; end if; select count(*) into numrows from paciente where paciente.usr_codimpressaocarteira = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; select count(*) into numrows from materialenviado where materialenviado.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialenviado.''; end if; select count(*) into numrows from materialidentificado where materialidentificado.usr_codretorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialidentificado.''; end if; select count(*) into numrows from materialidentificado where materialidentificado.usr_codenvio = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialidentificado.''; end if; select count(*) into numrows from loteapoio where loteapoio.usr_codrecebeucaixa = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteapoio.''; end if; select count(*) into numrows from examerequisicaosoroteca where examerequisicaosoroteca.usr_coddescarte = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosoroteca.''; end if; select count(*) into numrows from examerequisicaosoroteca where examerequisicaosoroteca.usr_codsoroteca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosoroteca.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codguiarepasse = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codrecoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codfaturarepasse = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcomissao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from montagemkit where montagemkit.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela montagemkit.''; end if; select count(*) into numrows from transfestoque where transfestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoque.''; end if; select count(*) into numrows from orcamento where orcamento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamento.''; end if; select count(*) into numrows from estoquemanual where estoquemanual.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela estoquemanual.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codalmoxarife = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codautorizafinanceira = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from conferenciaestoque where conferenciaestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codconciliacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from conferenciaentrada where conferenciaentrada.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaentrada.''; end if; select count(*) into numrows from conferenciaentrada where conferenciaentrada.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaentrada.''; end if; select count(*) into numrows from pedido where pedido.usr_codexclusao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from fatura where fatura.usr_codcomissao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from pedido where pedido.usr_codautorizacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from pedido where pedido.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from cotacao where cotacao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela cotacao.''; end if; select count(*) into numrows from material where material.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela material.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codprotestocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcartoriocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codavisocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codrepeticao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from paciente where paciente.usr_codalteracao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codguia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicaosituacoes where examerequisicaosituacoes.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosituacoes.''; end if; select count(*) into numrows from exames where exames.usr_codassinaweb = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela exames.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codexcluido = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codexcluida = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from fatura where fatura.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from convenios where convenios.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenios.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codreimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from geladeirastemperaturas where geladeirastemperaturas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela geladeirastemperaturas.''; end if; select count(*) into numrows from geladeiras where geladeiras.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela geladeiras.''; end if; delete from usuariofilial where usuariofilial.usr_codigo = old.usr_codigo; select count(*) into numrows from notafiscal where notafiscal.usr_codimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codcancelada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from baixa where baixa.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela baixa.''; end if; select count(*) into numrows from baixa where baixa.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela baixa.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from lanctocaixa where lanctocaixa.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctocaixa.''; end if; select count(*) into numrows from requisicaocid10 where requisicaocid10.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaocid10.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmaterialsetor = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codloteexterno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codenvio = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codcriacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from log where log.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela log.''; end if; select count(*) into numrows from usuariomensagem where usuariomensagem.usr_codorigem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuariomensagem.''; end if; delete from usuariomensagem where usuariomensagem.usr_coddestino = old.usr_codigo; select count(*) into numrows from conveniomensagem where conveniomensagem.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conveniomensagem.''; end if; select count(*) into numrows from examerequisicaorecipiente where examerequisicaorecipiente.usr_codtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaorecipiente.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codetqtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codetqcoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteapoio where loteapoio.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteapoio.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from fatura where fatura.usr_codconferencia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from fatura where fatura.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from contrasenha where contrasenha.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrasenha.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codnaofaturar = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicaousuario where requisicaousuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaousuario.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codabertura = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codcortesia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmapa = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from interfaceexamerequisicao where interfaceexamerequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela interfaceexamerequisicao.''; end if; select count(*) into numrows from usuarioparametro where usuarioparametro.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuarioparametro.''; end if; select count(*) into numrows from lanctocaixa where lanctocaixa.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctocaixa.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codentrega = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codfatura = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmaterial = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_coddigitador = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codassina = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; delete from usuarioacesso where usuarioacesso.usr_codigo = old.usr_codigo; select count(*) into numrows from setores where setores.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setores.''; end if; select count(*) into numrows from paciente where paciente.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; return old; end;' language 'plpgsql'; create trigger td_usuario after delete on usuario for each row execute procedure fn_td_usuario(); drop function fn_ti_usuario() cascade; create function fn_ti_usuario() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from tipousuario where new.tpu_codigo = tipousuario.tpu_codigo; tmp:=''tipousuario|''; tmp:=tmp || ''tpu_codigo='' || new.tpu_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.tpu_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela tipousuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_usuario after insert on usuario for each row execute procedure fn_ti_usuario(); drop function fn_tu_usuario() cascade; create function fn_tu_usuario() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexternologintegracao where labexternologintegracao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternologintegracao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexternoversaotermo where labexternoversaotermo.usr_codaceite = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternoversaotermo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from preagendamento where preagendamento.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from preagendamento where preagendamento.usr_codagendou = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_coddialsist = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from integracaosave where integracaosave.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela integracaosave.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from interfaceexamereagente where interfaceexamereagente.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela interfaceexamereagente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricoentrega where examerequisicaohistoricoentrega.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricoentrega.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaopaginasimpressas where requisicaopaginasimpressas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaopaginasimpressas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from tabelaprecoexamesusuario where tabelaprecoexamesusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela tabelaprecoexamesusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codenvioemail = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialusuario where materialusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logids where logids.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logids.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logvalidalotematerial where logvalidalotematerial.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logvalidalotematerial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from material where material.usr_codavisolote = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela material.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariosenhas where usuariosenhas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariosenhas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pacienteimagens where pacienteimagens.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pacienteimagens.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoimagens where requisicaoimagens.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoimagens.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamentoconvenio where orcamentoconvenio.usr_coddesconto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamentoconvenio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_coddesconto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaoetiquetas where examerequisicaoetiquetas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoetiquetas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codduplaconferencia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexternorequisicao where loteexternorequisicao.usr_codestorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexternorequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codestorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallotehistorico where materiallotehistorico.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallotehistorico.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codaberturainicial = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codfechado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codaberto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from responsavelcertificado where responsavelcertificado.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela responsavelcertificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codelegibilidade = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codsolicitadotiss = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codcoletar = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoquematerial where transfestoquematerial.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoquematerial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoque where transfestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaodadosbrutos where examerequisicaodadosbrutos.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaodadosbrutos.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaoincerteza where examerequisicaoincerteza.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoincerteza.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setoresnaoconformidadeusuario where setoresnaoconformidadeusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setoresnaoconformidadeusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setoresnaoconformidade where setoresnaoconformidade.usr_codresponsavelsetor = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setoresnaoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtransportechegada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtransportesaida = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lotefilial where lotefilial.usr_codrecebeu = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lotefilial where lotefilial.usr_codenviou = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logoffline where logoffline.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logoffline.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariologin where usuariologin.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariologin.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from acoesnaoconformidade where acoesnaoconformidade.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela acoesnaoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamentolog where orcamentolog.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamentolog.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamento where orcamento.usr_codaprovado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codconclusao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codanalise = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codregistro = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexterno where labexterno.usr_codconferir = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from banhomariatemperatura where banhomariatemperatura.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela banhomariatemperatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from banhomaria where banhomaria.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela banhomaria.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from filiais_postocoleta where filiais_postocoleta.usr_codcompras = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiais_postocoleta.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from filiais_postocoleta where filiais_postocoleta.usr_codestoque = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiais_postocoleta.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaolaminas where examerequisicaolaminas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaolaminas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codhorarioanexado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codbloqueado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codremovido = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohash where examerequisicaohash.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohash.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codfinalizado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codemcoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codremarcado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaolog where requisicaolog.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolog.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenioshistoricocota where convenioshistoricocota.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenioshistoricocota.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaotrocas where examerequisicaotrocas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaotrocas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtrocalayout = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codalteracaopreco = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariocompromisso where usuariocompromisso.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariocompromisso.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codsituacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrassenharequisicao where contrassenharequisicao.usr_codgerada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrassenharequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrassenharequisicao where contrassenharequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrassenharequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codentrega = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenioignorarecebimento where convenioignorarecebimento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenioignorarecebimento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosetor where examerequisicaosetor.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosetor.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codimpressaocarteira = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialenviado where materialenviado.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialenviado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialidentificado where materialidentificado.usr_codretorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialidentificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialidentificado where materialidentificado.usr_codenvio = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialidentificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteapoio where loteapoio.usr_codrecebeucaixa = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteapoio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosoroteca where examerequisicaosoroteca.usr_coddescarte = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosoroteca where examerequisicaosoroteca.usr_codsoroteca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codguiarepasse = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codrecoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codfaturarepasse = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcomissao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from montagemkit where montagemkit.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela montagemkit.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoque where transfestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamento where orcamento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from estoquemanual where estoquemanual.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela estoquemanual.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codalmoxarife = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codautorizafinanceira = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaestoque where conferenciaestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codconciliacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaentrada where conferenciaentrada.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaentrada.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaentrada where conferenciaentrada.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaentrada.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codexclusao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codcomissao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codautorizacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from cotacao where cotacao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela cotacao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from material where material.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela material.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codprotestocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcartoriocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codavisocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codrepeticao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codalteracao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codguia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosituacoes where examerequisicaosituacoes.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosituacoes.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from exames where exames.usr_codassinaweb = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exames.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codexcluido = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codexcluida = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenios where convenios.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenios.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codreimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from geladeirastemperaturas where geladeirastemperaturas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela geladeirastemperaturas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from geladeiras where geladeiras.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela geladeiras.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariofilial where usuariofilial.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariofilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codcancelada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from baixa where baixa.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela baixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from baixa where baixa.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela baixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctocaixa where lanctocaixa.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctocaixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaocid10 where requisicaocid10.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaocid10.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmaterialsetor = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codloteexterno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codenvio = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codcriacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from log where log.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela log.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariomensagem where usuariomensagem.usr_codorigem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariomensagem where usuariomensagem.usr_coddestino = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conveniomensagem where conveniomensagem.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conveniomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaorecipiente where examerequisicaorecipiente.usr_codtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaorecipiente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codetqtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codetqcoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteapoio where loteapoio.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteapoio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codconferencia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrasenha where contrasenha.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrasenha.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codnaofaturar = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaousuario where requisicaousuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaousuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codabertura = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codcortesia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmapa = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from interfaceexamerequisicao where interfaceexamerequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela interfaceexamerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuarioparametro where usuarioparametro.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuarioparametro.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctocaixa where lanctocaixa.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctocaixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codentrega = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codfatura = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmaterial = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_coddigitador = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codassina = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuarioacesso where usuarioacesso.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuarioacesso.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setores where setores.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setores.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; select count(*) into numrows from tipousuario where new.tpu_codigo = tipousuario.tpu_codigo; tmp:=''tipousuario|''; tmp:=tmp || ''tpu_codigo='' || new.tpu_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.tpu_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela tipousuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_usuario after update on usuario for each row execute procedure fn_tu_usuario(); select configurageralog('labexternoversaotermo'); insert into atualizacoes(atu_nome) values ('v21010001_040121.sql'); create table labexternolotepardini ( fil_codigo integer not null, lae_codigo integer not null, let_lote varchar(14) not null, let_datahoraenvio timestamp, let_dataprevisaoretorno varchar(20), let_datahoraretornou timestamp, let_qtdeexamesenviados integer ); create unique index xpklabexternolotepardini on labexternolotepardini ( fil_codigo, lae_codigo, let_lote ); create index xif1labexternolotepardini on labexternolotepardini ( fil_codigo, lae_codigo ); alter table labexternolotepardini add primary key (fil_codigo, lae_codigo, let_lote); drop function fn_td_labexterno() cascade; create function fn_td_labexterno() returns opaque as ' declare numrows integer; begin delete from labexternolotepardini where labexternolotepardini.fil_codigo = old.fil_codigo and labexternolotepardini.lae_codigo = old.lae_codigo; delete from labexternologintegracao where labexternologintegracao.fil_codigo = old.fil_codigo and labexternologintegracao.lae_codigo = old.lae_codigo; delete from labexternoversaotermo where labexternoversaotermo.fil_codigo = old.fil_codigo and labexternoversaotermo.lae_codigo = old.lae_codigo; select count(*) into numrows from examessaomarcos where examessaomarcos.fil_codigo = old.fil_codigo and examessaomarcos.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examessaomarcos.''; end if; delete from examessyslab where examessyslab.fil_codigo = old.fil_codigo and examessyslab.lae_codigo = old.lae_codigo; delete from examesunilab where examesunilab.fil_codigo = old.fil_codigo and examesunilab.lae_codigo = old.lae_codigo; select count(*) into numrows from filiais_postocoleta where filiais_postocoleta.fil_codigo = old.fil_codigo and filiais_postocoleta.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiais_postocoleta.''; end if; delete from logimportacaolabexterno where logimportacaolabexterno.fil_codigo = old.fil_codigo and logimportacaolabexterno.lae_codigo = old.lae_codigo; select count(*) into numrows from examessolucao where examessolucao.fil_codigo = old.fil_codigo and examessolucao.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examessolucao.''; end if; select count(*) into numrows from examesdb where examesdb.fil_codigo = old.fil_codigo and examesdb.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesdb.''; end if; delete from examesatitude where examesatitude.fil_codigo = old.fil_codigo and examesatitude.lae_codigo = old.lae_codigo; delete from examesbalague where examesbalague.fil_codigo = old.fil_codigo and examesbalague.lae_codigo = old.lae_codigo; delete from examesdelta where examesdelta.fil_codigo = old.fil_codigo and examesdelta.lae_codigo = old.lae_codigo; select count(*) into numrows from examematcoletalabexterno where examematcoletalabexterno.fil_codigo = old.fil_codigo and examematcoletalabexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examematcoletalabexterno.''; end if; select count(*) into numrows from examesmatrix where examesmatrix.fil_codigo = old.fil_codigo and examesmatrix.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesmatrix.''; end if; select count(*) into numrows from examesrede where examesrede.fil_codigo = old.fil_codigo and examesrede.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesrede.''; end if; delete from examesreacao where examesreacao.fil_codigo = old.fil_codigo and examesreacao.lae_codigo = old.lae_codigo; select count(*) into numrows from pacientelabexterno where pacientelabexterno.fil_codigo = old.fil_codigo and pacientelabexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pacientelabexterno.''; end if; select count(*) into numrows from requisicaolabexterno where requisicaolabexterno.fil_codigo = old.fil_codigo and requisicaolabexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolabexterno.''; end if; delete from examessergiofranco where examessergiofranco.fil_codigo = old.fil_codigo and examessergiofranco.lae_codigo = old.lae_codigo; delete from examesalvaro where examesalvaro.fil_codigo = old.fil_codigo and examesalvaro.lae_codigo = old.lae_codigo; select count(*) into numrows from examesjalis where examesjalis.fil_codigo = old.fil_codigo and examesjalis.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesjalis.''; end if; delete from examespardini where examespardini.fil_codigo = old.fil_codigo and examespardini.lae_codigo = old.lae_codigo; select count(*) into numrows from loteexterno where loteexterno.fil_codigo = old.fil_codigo and loteexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; return old; end;' language 'plpgsql'; create trigger td_labexterno after delete on labexterno for each row execute procedure fn_td_labexterno(); drop function fn_ti_labexterno() cascade; create function fn_ti_labexterno() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from prazoentrega where new.fil_codigo = prazoentrega.fil_codigo and new.prz_codigo = prazoentrega.prz_codigo; tmp:=''prazoentrega|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''prz_codigo='' || new.prz_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.prz_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela prazoentrega. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from setores where new.fil_codigo = setores.fil_codigo and new.set_codigo = setores.set_codigo; tmp:=''setores|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''set_codigo='' || new.set_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.set_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela setores. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codconferir = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codconferir || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codconferir is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_labexterno after insert on labexterno for each row execute procedure fn_ti_labexterno(); drop function fn_tu_labexterno() cascade; create function fn_tu_labexterno() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from labexternolotepardini where labexternolotepardini.fil_codigo = old.fil_codigo and labexternolotepardini.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternolotepardini.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from labexternologintegracao where labexternologintegracao.fil_codigo = old.fil_codigo and labexternologintegracao.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternologintegracao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from labexternoversaotermo where labexternoversaotermo.fil_codigo = old.fil_codigo and labexternoversaotermo.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternoversaotermo.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessaomarcos where examessaomarcos.fil_codigo = old.fil_codigo and examessaomarcos.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessaomarcos.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessyslab where examessyslab.fil_codigo = old.fil_codigo and examessyslab.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessyslab.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesunilab where examesunilab.fil_codigo = old.fil_codigo and examesunilab.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesunilab.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from filiais_postocoleta where filiais_postocoleta.fil_codigo = old.fil_codigo and filiais_postocoleta.lae_codigo = old.lae_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.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from logimportacaolabexterno where logimportacaolabexterno.fil_codigo = old.fil_codigo and logimportacaolabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logimportacaolabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessolucao where examessolucao.fil_codigo = old.fil_codigo and examessolucao.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessolucao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesdb where examesdb.fil_codigo = old.fil_codigo and examesdb.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesdb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesatitude where examesatitude.fil_codigo = old.fil_codigo and examesatitude.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesatitude.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesbalague where examesbalague.fil_codigo = old.fil_codigo and examesbalague.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesbalague.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesdelta where examesdelta.fil_codigo = old.fil_codigo and examesdelta.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesdelta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examematcoletalabexterno where examematcoletalabexterno.fil_codigo = old.fil_codigo and examematcoletalabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examematcoletalabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesmatrix where examesmatrix.fil_codigo = old.fil_codigo and examesmatrix.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesmatrix.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesrede where examesrede.fil_codigo = old.fil_codigo and examesrede.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesrede.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesreacao where examesreacao.fil_codigo = old.fil_codigo and examesreacao.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesreacao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from pacientelabexterno where pacientelabexterno.fil_codigo = old.fil_codigo and pacientelabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pacientelabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from requisicaolabexterno where requisicaolabexterno.fil_codigo = old.fil_codigo and requisicaolabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessergiofranco where examessergiofranco.fil_codigo = old.fil_codigo and examessergiofranco.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessergiofranco.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesalvaro where examesalvaro.fil_codigo = old.fil_codigo and examesalvaro.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesalvaro.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesjalis where examesjalis.fil_codigo = old.fil_codigo and examesjalis.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesjalis.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examespardini where examespardini.fil_codigo = old.fil_codigo and examespardini.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examespardini.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from loteexterno where loteexterno.fil_codigo = old.fil_codigo and loteexterno.lae_codigo = old.lae_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; select count(*) into numrows from prazoentrega where new.fil_codigo = prazoentrega.fil_codigo and new.prz_codigo = prazoentrega.prz_codigo; tmp:=''prazoentrega|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''prz_codigo='' || new.prz_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.prz_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela prazoentrega. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from setores where new.fil_codigo = setores.fil_codigo and new.set_codigo = setores.set_codigo; tmp:=''setores|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''set_codigo='' || new.set_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.set_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela setores. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codconferir = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codconferir || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codconferir is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_labexterno after update on labexterno for each row execute procedure fn_tu_labexterno(); --drop function fn_ti_labexternolotepardini() cascade; create function fn_ti_labexternolotepardini() 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 ( 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; return new; end;' language 'plpgsql'; create trigger ti_labexternolotepardini after insert on labexternolotepardini for each row execute procedure fn_ti_labexternolotepardini(); --drop function fn_tu_labexternolotepardini() cascade; create function fn_tu_labexternolotepardini() 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 ( 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; return old; end;' language 'plpgsql'; create trigger tu_labexternolotepardini after update on labexternolotepardini for each row execute procedure fn_tu_labexternolotepardini(); select configurageralog('labexternolotepardini'); insert into atualizacoes(atu_nome) values ('v21010002_040121.sql'); alter table labexterno add lae_codigomodeloweb integer default -1; insert into atualizacoes(atu_nome) values ('v21010003_070121.sql'); alter table requisicao add ent_codempresa integer; create index xif296requisicao on requisicao ( fil_codigo, ent_codempresa ); drop function fn_td_entidade() cascade; create function fn_td_entidade() returns opaque as ' declare numrows integer; begin select count(*) into numrows from requisicao where requisicao.fil_codigo = old.fil_codigo and requisicao.ent_codempresa = old.ent_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 naoconformidade where naoconformidade.fil_codigo = old.fil_codigo and naoconformidade.ent_codigo = old.ent_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 paciente where paciente.fil_codigo = old.fil_codigo and paciente.ent_codempresa = old.ent_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 pedido where pedido.fil_codigo = old.fil_codigo and pedido.ent_codigo = old.ent_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 cotacaoentidade where cotacaoentidade.fil_codigo = old.fil_codigo and cotacaoentidade.ent_codigo = old.ent_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela cotacaoentidade.''; end if; select count(*) into numrows from requisicao where requisicao.fil_codigo = old.fil_codigo and requisicao.ent_codigo = old.ent_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 convenioentidade where convenioentidade.fil_codigo = old.fil_codigo and convenioentidade.ent_codigo = old.ent_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenioentidade.''; end if; select count(*) into numrows from pacienteentidade where pacienteentidade.fil_codigo = old.fil_codigo and pacienteentidade.ent_codigo = old.ent_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pacienteentidade.''; end if; select count(*) into numrows from notafiscal where notafiscal.fil_codigo = old.fil_codigo and notafiscal.ent_codigo = old.ent_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 receberpagar where receberpagar.fil_codigo = old.fil_codigo and receberpagar.ent_codigo = old.ent_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; return old; end;' language 'plpgsql'; create trigger td_entidade after delete on entidade for each row execute procedure fn_td_entidade(); drop function fn_ti_entidade() cascade; create function fn_ti_entidade() returns opaque as ' declare numrows integer; tmp varchar; begin 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 ( 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 ( 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; 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_entidade after insert on entidade for each row execute procedure fn_ti_entidade(); drop function fn_tu_entidade() cascade; create function fn_tu_entidade() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.ent_codigo <> new.ent_codigo) then select count(*) from requisicao where requisicao.fil_codigo = old.fil_codigo and requisicao.ent_codempresa = old.ent_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 or old.ent_codigo <> new.ent_codigo) then select count(*) from naoconformidade where naoconformidade.fil_codigo = old.fil_codigo and naoconformidade.ent_codigo = old.ent_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 or old.ent_codigo <> new.ent_codigo) then select count(*) from paciente where paciente.fil_codigo = old.fil_codigo and paciente.ent_codempresa = old.ent_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.ent_codigo <> new.ent_codigo) then select count(*) from pedido where pedido.fil_codigo = old.fil_codigo and pedido.ent_codigo = old.ent_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 or old.ent_codigo <> new.ent_codigo) then select count(*) from cotacaoentidade where cotacaoentidade.fil_codigo = old.fil_codigo and cotacaoentidade.ent_codigo = old.ent_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela cotacaoentidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.ent_codigo <> new.ent_codigo) then select count(*) from requisicao where requisicao.fil_codigo = old.fil_codigo and requisicao.ent_codigo = old.ent_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 or old.ent_codigo <> new.ent_codigo) then select count(*) from convenioentidade where convenioentidade.fil_codigo = old.fil_codigo and convenioentidade.ent_codigo = old.ent_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenioentidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.ent_codigo <> new.ent_codigo) then select count(*) from pacienteentidade where pacienteentidade.fil_codigo = old.fil_codigo and pacienteentidade.ent_codigo = old.ent_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pacienteentidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.ent_codigo <> new.ent_codigo) then select count(*) from notafiscal where notafiscal.fil_codigo = old.fil_codigo and notafiscal.ent_codigo = old.ent_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 or old.ent_codigo <> new.ent_codigo) then select count(*) from receberpagar where receberpagar.fil_codigo = old.fil_codigo and receberpagar.ent_codigo = old.ent_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; 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 ( 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 ( 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; 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_entidade after update on entidade for each row execute procedure fn_tu_entidade(); drop function fn_td_requisicao() cascade; create function fn_td_requisicao() returns opaque as ' declare numrows integer; begin delete from logpushapp where logpushapp.fil_codigo = old.fil_codigo and logpushapp.req_codigo = old.req_codigo; select count(*) into numrows from requisicaopaginasimpressas where requisicaopaginasimpressas.fil_codigo = old.fil_codigo and requisicaopaginasimpressas.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaopaginasimpressas.''; end if; select count(*) into numrows from exportaintegracaohospital where exportaintegracaohospital.fil_codigo = old.fil_codigo and exportaintegracaohospital.req_codigo = old.req_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 logemail where logemail.fil_codigo = old.fil_codigo and logemail.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logemail.''; end if; delete from requisicaovisualizada where requisicaovisualizada.fil_codigo = old.fil_codigo and requisicaovisualizada.req_codigo = old.req_codigo; delete from exportaintegracaooperadora where exportaintegracaooperadora.fil_codigo = old.fil_codigo and exportaintegracaooperadora.req_codigo = old.req_codigo; delete from requisicaoimagens where requisicaoimagens.fil_codigo = old.fil_codigo and requisicaoimagens.req_codigo = old.req_codigo; delete from logsms where logsms.fil_codigo = old.fil_codigo and logsms.req_codigo = old.req_codigo; select count(*) into numrows from requisicaotaxa where requisicaotaxa.fil_codigo = old.fil_codigo and requisicaotaxa.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaotaxa.''; end if; select count(*) into numrows from lotefilialrequisicao where lotefilialrequisicao.fil_codigo = old.fil_codigo and lotefilialrequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilialrequisicao.''; end if; select count(*) into numrows from requisicaonaoconformidade where requisicaonaoconformidade.fil_codigo = old.fil_codigo and requisicaonaoconformidade.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaonaoconformidade.''; end if; select count(*) into numrows from requisicaolog where requisicaolog.fil_codigo = old.fil_codigo and requisicaolog.req_codigo = old.req_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 agendamento where agendamento.fil_codigo = old.fil_codigo and agendamento.req_codigo = old.req_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 and requisicaoweb.req_codigo = old.req_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 requisicaonotafiscal where requisicaonotafiscal.fil_codigo = old.fil_codigo and requisicaonotafiscal.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaonotafiscal.''; end if; select count(*) into numrows from requisicaolabexterno where requisicaolabexterno.fil_codigo = old.fil_codigo and requisicaolabexterno.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolabexterno.''; end if; delete from requisicaocid10 where requisicaocid10.fil_codigo = old.fil_codigo and requisicaocid10.req_codigo = old.req_codigo; select count(*) into numrows from loteexternorequisicao where loteexternorequisicao.fil_kodigo = old.fil_codigo and loteexternorequisicao.req_codigo = old.req_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 loteapoiorequisicao where loteapoiorequisicao.fil_codigo = old.fil_codigo and loteapoiorequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteapoiorequisicao.''; end if; delete from requisicaousuario where requisicaousuario.fil_codigo = old.fil_codigo and requisicaousuario.req_codigo = old.req_codigo; delete from requisicaolanctocaixa where requisicaolanctocaixa.fil_codigo = old.fil_codigo and requisicaolanctocaixa.req_codigo = old.req_codigo; delete from examescontrole where examescontrole.fil_codigo = old.fil_codigo and examescontrole.req_codigo = old.req_codigo; select count(*) into numrows from requisicaorequisicao where requisicaorequisicao.fil_codigo = old.fil_codigo and requisicaorequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaorequisicao.''; end if; delete from requisicaomedicamento where requisicaomedicamento.fil_codigo = old.fil_codigo and requisicaomedicamento.req_codigo = old.req_codigo; select count(*) into numrows from faturarequisicao where faturarequisicao.fil_kodigo = old.fil_codigo and faturarequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela faturarequisicao.''; end if; delete from requisicaorequisicao where requisicaorequisicao.fil_codigo = old.fil_codigo and requisicaorequisicao.req_kodigo = old.req_codigo; delete from examerequisicao where examerequisicao.fil_codigo = old.fil_codigo and examerequisicao.req_codigo = old.req_codigo; return old; end;' language 'plpgsql'; create trigger td_requisicao after delete on requisicao for each row execute procedure fn_td_requisicao(); drop function fn_ti_requisicao() cascade; create function fn_ti_requisicao() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from entidade where new.fil_codigo = entidade.fil_codigo and new.ent_codempresa = entidade.ent_codigo; tmp:=''entidade|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''ent_codigo='' || new.ent_codempresa || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.ent_codempresa is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela entidade. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from produtoalimentos where new.fil_codigo = produtoalimentos.fil_codigo and new.cpl_codigo = produtoalimentos.cpl_codigo and new.pal_codigo = produtoalimentos.pal_codigo; tmp:=''produtoalimentos|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''cpl_codigo='' || new.cpl_codigo || ''|''; tmp:=tmp || ''pal_codigo='' || new.pal_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.cpl_codigo is not null and new.pal_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela produtoalimentos. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_coddesconto = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_coddesconto || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_coddesconto 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_codelegibilidade = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codelegibilidade || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codelegibilidade 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 formapagto where new.fpg_codigo = formapagto.fpg_codigo and new.fil_codigo = formapagto.fil_codigo; tmp:=''formapagto|''; tmp:=tmp || ''fpg_codigo='' || new.fpg_codigo || ''|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fpg_codigo is not null and 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 formapagto. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from pais where new.fil_codigo = pais.fil_codigo and new.pai_codigo = pais.pai_codigo; tmp:=''pais|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pai_codigo='' || new.pai_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.pai_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela pais. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codguiarepasse = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codguiarepasse || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codguiarepasse 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 convenios where new.fil_codigo = convenios.fil_codigo and new.con_codrepasse = convenios.con_codigo; tmp:=''convenios|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''con_codigo='' || new.con_codrepasse || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.con_codrepasse is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela convenios. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from orcamento where new.fil_codigo = orcamento.fil_codigo and new.orc_codigo = orcamento.orc_codigo; tmp:=''orcamento|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''orc_codigo='' || new.orc_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.orc_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela orcamento. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from unidadesaude where new.fil_codigo = unidadesaude.fil_codigo and new.uns_codigo = unidadesaude.uns_codigo; tmp:=''unidadesaude|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''uns_codigo='' || new.uns_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.uns_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela unidadesaude. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codexcluida = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codexcluida || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codexcluida 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 entidade where new.fil_codigo = entidade.fil_codigo and new.ent_codigo = entidade.ent_codigo; tmp:=''entidade|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''ent_codigo='' || new.ent_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.ent_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela entidade. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from embalagemproduto where new.fil_codigo = embalagemproduto.fil_codigo and new.emb_codigo = embalagemproduto.emb_codigo; tmp:=''embalagemproduto|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''emb_codigo='' || new.emb_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.emb_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela embalagemproduto. 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 situacao where new.fil_codigo = situacao.fil_codigo and new.sit_codigo = situacao.sit_codigo; tmp:=''situacao|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''sit_codigo='' || new.sit_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.sit_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela situacao. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from alahospital where new.fil_codigo = alahospital.fil_codigo and new.ala_codigo = alahospital.ala_codigo; tmp:=''alahospital|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''ala_codigo='' || new.ala_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.ala_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela alahospital. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codcopia = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codcopia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codcopia is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codabertura = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codabertura || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codabertura 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 estacoes where new.est_codigo = estacoes.est_codigo; tmp:=''estacoes|''; tmp:=tmp || ''est_codigo='' || new.est_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.est_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela estacoes. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_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 coletas where new.fil_codigo = coletas.fil_codigo and new.col_codigo = coletas.col_codigo; tmp:=''coletas|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''col_codigo='' || new.col_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.col_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela coletas. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from destino where new.fil_codigo = destino.fil_codigo and new.des_codigo = destino.des_codigo; tmp:=''destino|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''des_codigo='' || new.des_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.des_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela destino. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from convenios where new.fil_codigo = convenios.fil_codigo and new.con_codigo = convenios.con_codigo; tmp:=''convenios|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''con_codigo='' || new.con_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.con_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela convenios. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from medico where new.fil_codigo = medico.fil_codigo and new.med_conselho = medico.med_conselho and new.med_crm = medico.med_crm and new.med_uf = medico.med_uf; tmp:=''medico|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''med_conselho='' || new.med_conselho || ''|''; tmp:=tmp || ''med_crm='' || new.med_crm || ''|''; tmp:=tmp || ''med_uf='' || new.med_uf || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.med_conselho is not null and new.med_crm is not null and new.med_uf is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela medico. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from paciente where new.fil_codigo = paciente.fil_codigo and new.pac_codigo = paciente.pac_codigo; tmp:=''paciente|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pac_codigo='' || new.pac_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 paciente. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_requisicao after insert on requisicao for each row execute procedure fn_ti_requisicao(); drop function fn_tu_requisicao() cascade; create function fn_tu_requisicao() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from logpushapp where logpushapp.fil_codigo = old.fil_codigo and logpushapp.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logpushapp.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaopaginasimpressas where requisicaopaginasimpressas.fil_codigo = old.fil_codigo and requisicaopaginasimpressas.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaopaginasimpressas.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from exportaintegracaohospital where exportaintegracaohospital.fil_codigo = old.fil_codigo and exportaintegracaohospital.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exportaintegracaohospital.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from logemail where logemail.fil_codigo = old.fil_codigo and logemail.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logemail.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaovisualizada where requisicaovisualizada.fil_codigo = old.fil_codigo and requisicaovisualizada.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaovisualizada.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from exportaintegracaooperadora where exportaintegracaooperadora.fil_codigo = old.fil_codigo and exportaintegracaooperadora.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exportaintegracaooperadora.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaoimagens where requisicaoimagens.fil_codigo = old.fil_codigo and requisicaoimagens.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoimagens.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from logsms where logsms.fil_codigo = old.fil_codigo and logsms.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logsms.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaotaxa where requisicaotaxa.fil_codigo = old.fil_codigo and requisicaotaxa.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaotaxa.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from lotefilialrequisicao where lotefilialrequisicao.fil_codigo = old.fil_codigo and lotefilialrequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilialrequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaonaoconformidade where requisicaonaoconformidade.fil_codigo = old.fil_codigo and requisicaonaoconformidade.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaonaoconformidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaolog where requisicaolog.fil_codigo = old.fil_codigo and requisicaolog.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolog.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from agendamento where agendamento.fil_codigo = old.fil_codigo and agendamento.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaoweb where requisicaoweb.fil_codigo = old.fil_codigo and requisicaoweb.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoweb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaonotafiscal where requisicaonotafiscal.fil_codigo = old.fil_codigo and requisicaonotafiscal.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaonotafiscal.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaolabexterno where requisicaolabexterno.fil_codigo = old.fil_codigo and requisicaolabexterno.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaocid10 where requisicaocid10.fil_codigo = old.fil_codigo and requisicaocid10.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaocid10.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from loteexternorequisicao where loteexternorequisicao.fil_kodigo = old.fil_codigo and loteexternorequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexternorequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from loteapoiorequisicao where loteapoiorequisicao.fil_codigo = old.fil_codigo and loteapoiorequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteapoiorequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaousuario where requisicaousuario.fil_codigo = old.fil_codigo and requisicaousuario.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaousuario.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaolanctocaixa where requisicaolanctocaixa.fil_codigo = old.fil_codigo and requisicaolanctocaixa.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolanctocaixa.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examescontrole where examescontrole.fil_codigo = old.fil_codigo and examescontrole.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examescontrole.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaorequisicao where requisicaorequisicao.fil_codigo = old.fil_codigo and requisicaorequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaorequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaomedicamento where requisicaomedicamento.fil_codigo = old.fil_codigo and requisicaomedicamento.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaomedicamento.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from faturarequisicao where faturarequisicao.fil_kodigo = old.fil_codigo and faturarequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela faturarequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaorequisicao where requisicaorequisicao.fil_codigo = old.fil_codigo and requisicaorequisicao.req_kodigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaorequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicao where examerequisicao.fil_codigo = old.fil_codigo and examerequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; select count(*) into numrows from entidade where new.fil_codigo = entidade.fil_codigo and new.ent_codempresa = entidade.ent_codigo; tmp:=''entidade|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''ent_codigo='' || new.ent_codempresa || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.ent_codempresa is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela entidade. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from produtoalimentos where new.fil_codigo = produtoalimentos.fil_codigo and new.cpl_codigo = produtoalimentos.cpl_codigo and new.pal_codigo = produtoalimentos.pal_codigo; tmp:=''produtoalimentos|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''cpl_codigo='' || new.cpl_codigo || ''|''; tmp:=tmp || ''pal_codigo='' || new.pal_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.cpl_codigo is not null and new.pal_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela produtoalimentos. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_coddesconto = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_coddesconto || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_coddesconto 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_codelegibilidade = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codelegibilidade || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codelegibilidade 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 formapagto where new.fpg_codigo = formapagto.fpg_codigo and new.fil_codigo = formapagto.fil_codigo; tmp:=''formapagto|''; tmp:=tmp || ''fpg_codigo='' || new.fpg_codigo || ''|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fpg_codigo is not null and 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 formapagto. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from pais where new.fil_codigo = pais.fil_codigo and new.pai_codigo = pais.pai_codigo; tmp:=''pais|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pai_codigo='' || new.pai_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.pai_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela pais. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codguiarepasse = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codguiarepasse || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codguiarepasse 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 convenios where new.fil_codigo = convenios.fil_codigo and new.con_codrepasse = convenios.con_codigo; tmp:=''convenios|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''con_codigo='' || new.con_codrepasse || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.con_codrepasse is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela convenios. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from orcamento where new.fil_codigo = orcamento.fil_codigo and new.orc_codigo = orcamento.orc_codigo; tmp:=''orcamento|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''orc_codigo='' || new.orc_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.orc_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela orcamento. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from unidadesaude where new.fil_codigo = unidadesaude.fil_codigo and new.uns_codigo = unidadesaude.uns_codigo; tmp:=''unidadesaude|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''uns_codigo='' || new.uns_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.uns_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela unidadesaude. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codexcluida = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codexcluida || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codexcluida 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 entidade where new.fil_codigo = entidade.fil_codigo and new.ent_codigo = entidade.ent_codigo; tmp:=''entidade|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''ent_codigo='' || new.ent_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.ent_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela entidade. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from embalagemproduto where new.fil_codigo = embalagemproduto.fil_codigo and new.emb_codigo = embalagemproduto.emb_codigo; tmp:=''embalagemproduto|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''emb_codigo='' || new.emb_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.emb_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela embalagemproduto. 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 situacao where new.fil_codigo = situacao.fil_codigo and new.sit_codigo = situacao.sit_codigo; tmp:=''situacao|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''sit_codigo='' || new.sit_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.sit_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela situacao. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from alahospital where new.fil_codigo = alahospital.fil_codigo and new.ala_codigo = alahospital.ala_codigo; tmp:=''alahospital|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''ala_codigo='' || new.ala_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.ala_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela alahospital. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codcopia = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codcopia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codcopia is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codabertura = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codabertura || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codabertura 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 estacoes where new.est_codigo = estacoes.est_codigo; tmp:=''estacoes|''; tmp:=tmp || ''est_codigo='' || new.est_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.est_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela estacoes. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_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 coletas where new.fil_codigo = coletas.fil_codigo and new.col_codigo = coletas.col_codigo; tmp:=''coletas|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''col_codigo='' || new.col_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.col_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela coletas. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from destino where new.fil_codigo = destino.fil_codigo and new.des_codigo = destino.des_codigo; tmp:=''destino|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''des_codigo='' || new.des_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.des_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela destino. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from convenios where new.fil_codigo = convenios.fil_codigo and new.con_codigo = convenios.con_codigo; tmp:=''convenios|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''con_codigo='' || new.con_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.con_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela convenios. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from medico where new.fil_codigo = medico.fil_codigo and new.med_conselho = medico.med_conselho and new.med_crm = medico.med_crm and new.med_uf = medico.med_uf; tmp:=''medico|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''med_conselho='' || new.med_conselho || ''|''; tmp:=tmp || ''med_crm='' || new.med_crm || ''|''; tmp:=tmp || ''med_uf='' || new.med_uf || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.med_conselho is not null and new.med_crm is not null and new.med_uf is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela medico. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from paciente where new.fil_codigo = paciente.fil_codigo and new.pac_codigo = paciente.pac_codigo; tmp:=''paciente|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pac_codigo='' || new.pac_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 paciente. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_requisicao after update on requisicao for each row execute procedure fn_tu_requisicao(); insert into atualizacoes(atu_nome) values ('v21010004_130121.sql'); alter table requisicao add req_datainiciocoletasalux timestamp, add req_idsolicitacaosalux varchar(17); alter table examerequisicao add exr_sequencialsalux integer; alter table medico add med_integracao varchar(20); insert into atualizacoes(atu_nome) values ('v21010005_150121.sql'); alter table paciente add pac_generosexo varchar(1); insert into atualizacoes(atu_nome) values ('v21010006_220121.sql'); drop table preagendamentoimagem cascade; create table preagendamentoevento ( fil_codigo integer not null, pre_codigo integer not null, pee_codigo integer not null, pee_tipo varchar(1), pee_datahora timestamp, pee_motivo varchar(5000), usr_codigo varchar(20) ); create unique index xpkpreagendamentoevento on preagendamentoevento ( fil_codigo, pre_codigo, pee_codigo ); create index xif1preagendamentoevento on preagendamentoevento ( fil_codigo, pre_codigo ); create index xif2preagendamentoevento on preagendamentoevento ( usr_codigo ); alter table preagendamentoevento add primary key (fil_codigo, pre_codigo, pee_codigo); create table preagendamentoimagem ( fil_codigo integer not null, pre_codigo integer not null, pig_codigo integer not null, pig_tipo varchar(1), pig_imagem text ); create unique index xpkpreagendamentoimagem on preagendamentoimagem ( fil_codigo, pre_codigo, pig_codigo ); create index xif1preagendamentoimagem on preagendamentoimagem ( fil_codigo, pre_codigo ); alter table preagendamentoimagem add primary key (fil_codigo, pre_codigo, pig_codigo); drop function fn_td_preagendamento() cascade; create function fn_td_preagendamento() returns opaque as ' declare numrows integer; begin delete from preagendamentoevento where preagendamentoevento.fil_codigo = old.fil_codigo and preagendamentoevento.pre_codigo = old.pre_codigo; delete from preagendamentoimagem where preagendamentoimagem.fil_codigo = old.fil_codigo and preagendamentoimagem.pre_codigo = old.pre_codigo; delete from preagendamentoexame where preagendamentoexame.fil_codigo = old.fil_codigo and preagendamentoexame.pre_codigo = old.pre_codigo; return old; end;' language 'plpgsql'; create trigger td_preagendamento after delete on preagendamento for each row execute procedure fn_td_preagendamento(); drop function fn_ti_preagendamento() cascade; create function fn_ti_preagendamento() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_codcancelamento = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcancelamento || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcancelamento is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codagendou = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codagendou || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codagendou is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_preagendamento after insert on preagendamento for each row execute procedure fn_ti_preagendamento(); drop function fn_tu_preagendamento() cascade; create function fn_tu_preagendamento() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.pre_codigo <> new.pre_codigo) then select count(*) from preagendamentoevento where preagendamentoevento.fil_codigo = old.fil_codigo and preagendamentoevento.pre_codigo = old.pre_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamentoevento.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.pre_codigo <> new.pre_codigo) then select count(*) from preagendamentoimagem where preagendamentoimagem.fil_codigo = old.fil_codigo and preagendamentoimagem.pre_codigo = old.pre_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamentoimagem.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.pre_codigo <> new.pre_codigo) then select count(*) from preagendamentoexame where preagendamentoexame.fil_codigo = old.fil_codigo and preagendamentoexame.pre_codigo = old.pre_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamentoexame.''; end if; end if; select count(*) into numrows from usuario where new.usr_codcancelamento = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codcancelamento || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codcancelamento is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codagendou = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codagendou || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codagendou is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_preagendamento after update on preagendamento for each row execute procedure fn_tu_preagendamento(); --drop function fn_ti_preagendamentoevento() cascade; create function fn_ti_preagendamentoevento() 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 preagendamento where new.fil_codigo = preagendamento.fil_codigo and new.pre_codigo = preagendamento.pre_codigo; tmp:=''preagendamento|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pre_codigo='' || new.pre_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela preagendamento. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_preagendamentoevento after insert on preagendamentoevento for each row execute procedure fn_ti_preagendamentoevento(); --drop function fn_tu_preagendamentoevento() cascade; create function fn_tu_preagendamentoevento() 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 preagendamento where new.fil_codigo = preagendamento.fil_codigo and new.pre_codigo = preagendamento.pre_codigo; tmp:=''preagendamento|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pre_codigo='' || new.pre_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela preagendamento. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_preagendamentoevento after update on preagendamentoevento for each row execute procedure fn_tu_preagendamentoevento(); drop function fn_ti_preagendamentoimagem() cascade; create function fn_ti_preagendamentoimagem() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from preagendamento where new.fil_codigo = preagendamento.fil_codigo and new.pre_codigo = preagendamento.pre_codigo; tmp:=''preagendamento|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pre_codigo='' || new.pre_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela preagendamento. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_preagendamentoimagem after insert on preagendamentoimagem for each row execute procedure fn_ti_preagendamentoimagem(); drop function fn_tu_preagendamentoimagem() cascade; create function fn_tu_preagendamentoimagem() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from preagendamento where new.fil_codigo = preagendamento.fil_codigo and new.pre_codigo = preagendamento.pre_codigo; tmp:=''preagendamento|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pre_codigo='' || new.pre_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela preagendamento. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_preagendamentoimagem after update on preagendamentoimagem for each row execute procedure fn_tu_preagendamentoimagem(); drop function fn_td_usuario() cascade; create function fn_td_usuario() returns opaque as ' declare numrows integer; begin select count(*) into numrows from preagendamentoevento where preagendamentoevento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamentoevento.''; end if; select count(*) into numrows from labexternologintegracao where labexternologintegracao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexternologintegracao.''; end if; select count(*) into numrows from labexternoversaotermo where labexternoversaotermo.usr_codaceite = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexternoversaotermo.''; end if; select count(*) into numrows from preagendamento where preagendamento.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamento.''; end if; select count(*) into numrows from preagendamento where preagendamento.usr_codagendou = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamento.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_coddialsist = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from integracaosave where integracaosave.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela integracaosave.''; end if; select count(*) into numrows from interfaceexamereagente where interfaceexamereagente.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela interfaceexamereagente.''; end if; select count(*) into numrows from examerequisicaohistoricoentrega where examerequisicaohistoricoentrega.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricoentrega.''; end if; select count(*) into numrows from requisicaopaginasimpressas where requisicaopaginasimpressas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaopaginasimpressas.''; end if; select count(*) into numrows from tabelaprecoexamesusuario where tabelaprecoexamesusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela tabelaprecoexamesusuario.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codenvioemail = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from materialusuario where materialusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialusuario.''; end if; select count(*) into numrows from logids where logids.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logids.''; end if; select count(*) into numrows from logvalidalotematerial where logvalidalotematerial.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logvalidalotematerial.''; end if; select count(*) into numrows from material where material.usr_codavisolote = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela material.''; end if; delete from usuariosenhas where usuariosenhas.usr_codigo = old.usr_codigo; select count(*) into numrows from pacienteimagens where pacienteimagens.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pacienteimagens.''; end if; select count(*) into numrows from requisicaoimagens where requisicaoimagens.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoimagens.''; end if; select count(*) into numrows from orcamentoconvenio where orcamentoconvenio.usr_coddesconto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamentoconvenio.''; end if; select count(*) into numrows from requisicao where requisicao.usr_coddesconto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicaoetiquetas where examerequisicaoetiquetas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaoetiquetas.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codduplaconferencia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteexternorequisicao where loteexternorequisicao.usr_codestorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexternorequisicao.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codestorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from materiallotehistorico where materiallotehistorico.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallotehistorico.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codaberturainicial = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codfechado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codaberto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; delete from responsavelcertificado where responsavelcertificado.usr_codigo = old.usr_codigo; select count(*) into numrows from requisicao where requisicao.usr_codelegibilidade = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codsolicitadotiss = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codcoletar = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from transfestoquematerial where transfestoquematerial.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoquematerial.''; end if; select count(*) into numrows from transfestoque where transfestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoque.''; end if; select count(*) into numrows from examerequisicaodadosbrutos where examerequisicaodadosbrutos.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaodadosbrutos.''; end if; select count(*) into numrows from examerequisicaoincerteza where examerequisicaoincerteza.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaoincerteza.''; end if; select count(*) into numrows from setoresnaoconformidadeusuario where setoresnaoconformidadeusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setoresnaoconformidadeusuario.''; end if; select count(*) into numrows from setoresnaoconformidade where setoresnaoconformidade.usr_codresponsavelsetor = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setoresnaoconformidade.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtransportechegada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtransportesaida = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from lotefilial where lotefilial.usr_codrecebeu = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilial.''; end if; select count(*) into numrows from lotefilial where lotefilial.usr_codenviou = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilial.''; end if; select count(*) into numrows from logoffline where logoffline.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logoffline.''; end if; select count(*) into numrows from usuariologin where usuariologin.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuariologin.''; end if; select count(*) into numrows from acoesnaoconformidade where acoesnaoconformidade.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela acoesnaoconformidade.''; end if; select count(*) into numrows from orcamentolog where orcamentolog.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamentolog.''; end if; select count(*) into numrows from orcamento where orcamento.usr_codaprovado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamento.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codconclusao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codanalise = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codregistro = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from labexterno where labexterno.usr_codconferir = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexterno.''; end if; select count(*) into numrows from banhomariatemperatura where banhomariatemperatura.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela banhomariatemperatura.''; end if; select count(*) into numrows from banhomaria where banhomaria.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela banhomaria.''; end if; select count(*) into numrows from filiais_postocoleta where filiais_postocoleta.usr_codcompras = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiais_postocoleta.''; end if; select count(*) into numrows from filiais_postocoleta where filiais_postocoleta.usr_codestoque = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiais_postocoleta.''; end if; select count(*) into numrows from examerequisicaolaminas where examerequisicaolaminas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaolaminas.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codhorarioanexado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codbloqueado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codremovido = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from examerequisicaohash where examerequisicaohash.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohash.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codfinalizado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codemcoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codremarcado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from requisicaolog where requisicaolog.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolog.''; end if; select count(*) into numrows from convenioshistoricocota where convenioshistoricocota.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenioshistoricocota.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from examerequisicaotrocas where examerequisicaotrocas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaotrocas.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtrocalayout = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codalteracaopreco = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; delete from usuariocompromisso where usuariocompromisso.usr_codigo = old.usr_codigo; select count(*) into numrows from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codsituacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; select count(*) into numrows from contrassenharequisicao where contrassenharequisicao.usr_codgerada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrassenharequisicao.''; end if; select count(*) into numrows from contrassenharequisicao where contrassenharequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrassenharequisicao.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codentrega = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from convenioignorarecebimento where convenioignorarecebimento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenioignorarecebimento.''; end if; select count(*) into numrows from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; select count(*) into numrows from examerequisicaosetor where examerequisicaosetor.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosetor.''; end if; select count(*) into numrows from paciente where paciente.usr_codimpressaocarteira = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; select count(*) into numrows from materialenviado where materialenviado.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialenviado.''; end if; select count(*) into numrows from materialidentificado where materialidentificado.usr_codretorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialidentificado.''; end if; select count(*) into numrows from materialidentificado where materialidentificado.usr_codenvio = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialidentificado.''; end if; select count(*) into numrows from loteapoio where loteapoio.usr_codrecebeucaixa = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteapoio.''; end if; select count(*) into numrows from examerequisicaosoroteca where examerequisicaosoroteca.usr_coddescarte = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosoroteca.''; end if; select count(*) into numrows from examerequisicaosoroteca where examerequisicaosoroteca.usr_codsoroteca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosoroteca.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codguiarepasse = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codrecoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codfaturarepasse = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcomissao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from montagemkit where montagemkit.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela montagemkit.''; end if; select count(*) into numrows from transfestoque where transfestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoque.''; end if; select count(*) into numrows from orcamento where orcamento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamento.''; end if; select count(*) into numrows from estoquemanual where estoquemanual.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela estoquemanual.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codalmoxarife = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codautorizafinanceira = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from conferenciaestoque where conferenciaestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codconciliacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from conferenciaentrada where conferenciaentrada.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaentrada.''; end if; select count(*) into numrows from conferenciaentrada where conferenciaentrada.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaentrada.''; end if; select count(*) into numrows from pedido where pedido.usr_codexclusao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from fatura where fatura.usr_codcomissao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from pedido where pedido.usr_codautorizacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from pedido where pedido.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from cotacao where cotacao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela cotacao.''; end if; select count(*) into numrows from material where material.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela material.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codprotestocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcartoriocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codavisocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codrepeticao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from paciente where paciente.usr_codalteracao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codguia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicaosituacoes where examerequisicaosituacoes.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosituacoes.''; end if; select count(*) into numrows from exames where exames.usr_codassinaweb = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela exames.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codexcluido = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codexcluida = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from fatura where fatura.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from convenios where convenios.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenios.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codreimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from geladeirastemperaturas where geladeirastemperaturas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela geladeirastemperaturas.''; end if; select count(*) into numrows from geladeiras where geladeiras.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela geladeiras.''; end if; delete from usuariofilial where usuariofilial.usr_codigo = old.usr_codigo; select count(*) into numrows from notafiscal where notafiscal.usr_codimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codcancelada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from baixa where baixa.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela baixa.''; end if; select count(*) into numrows from baixa where baixa.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela baixa.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from lanctocaixa where lanctocaixa.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctocaixa.''; end if; select count(*) into numrows from requisicaocid10 where requisicaocid10.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaocid10.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmaterialsetor = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codloteexterno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codenvio = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codcriacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from log where log.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela log.''; end if; select count(*) into numrows from usuariomensagem where usuariomensagem.usr_codorigem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuariomensagem.''; end if; delete from usuariomensagem where usuariomensagem.usr_coddestino = old.usr_codigo; select count(*) into numrows from conveniomensagem where conveniomensagem.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conveniomensagem.''; end if; select count(*) into numrows from examerequisicaorecipiente where examerequisicaorecipiente.usr_codtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaorecipiente.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codetqtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codetqcoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteapoio where loteapoio.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteapoio.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from fatura where fatura.usr_codconferencia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from fatura where fatura.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from contrasenha where contrasenha.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrasenha.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codnaofaturar = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicaousuario where requisicaousuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaousuario.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codabertura = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codcortesia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmapa = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from interfaceexamerequisicao where interfaceexamerequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela interfaceexamerequisicao.''; end if; select count(*) into numrows from usuarioparametro where usuarioparametro.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuarioparametro.''; end if; select count(*) into numrows from lanctocaixa where lanctocaixa.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctocaixa.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codentrega = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codfatura = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmaterial = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_coddigitador = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codassina = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; delete from usuarioacesso where usuarioacesso.usr_codigo = old.usr_codigo; select count(*) into numrows from setores where setores.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setores.''; end if; select count(*) into numrows from paciente where paciente.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; return old; end;' language 'plpgsql'; create trigger td_usuario after delete on usuario for each row execute procedure fn_td_usuario(); drop function fn_ti_usuario() cascade; create function fn_ti_usuario() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from tipousuario where new.tpu_codigo = tipousuario.tpu_codigo; tmp:=''tipousuario|''; tmp:=tmp || ''tpu_codigo='' || new.tpu_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.tpu_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela tipousuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_usuario after insert on usuario for each row execute procedure fn_ti_usuario(); drop function fn_tu_usuario() cascade; create function fn_tu_usuario() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.usr_codigo <> new.usr_codigo) then select count(*) from preagendamentoevento where preagendamentoevento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamentoevento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexternologintegracao where labexternologintegracao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternologintegracao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexternoversaotermo where labexternoversaotermo.usr_codaceite = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternoversaotermo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from preagendamento where preagendamento.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from preagendamento where preagendamento.usr_codagendou = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_coddialsist = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from integracaosave where integracaosave.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela integracaosave.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from interfaceexamereagente where interfaceexamereagente.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela interfaceexamereagente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricoentrega where examerequisicaohistoricoentrega.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricoentrega.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaopaginasimpressas where requisicaopaginasimpressas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaopaginasimpressas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from tabelaprecoexamesusuario where tabelaprecoexamesusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela tabelaprecoexamesusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codenvioemail = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialusuario where materialusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logids where logids.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logids.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logvalidalotematerial where logvalidalotematerial.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logvalidalotematerial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from material where material.usr_codavisolote = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela material.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariosenhas where usuariosenhas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariosenhas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pacienteimagens where pacienteimagens.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pacienteimagens.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoimagens where requisicaoimagens.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoimagens.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamentoconvenio where orcamentoconvenio.usr_coddesconto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamentoconvenio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_coddesconto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaoetiquetas where examerequisicaoetiquetas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoetiquetas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codduplaconferencia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexternorequisicao where loteexternorequisicao.usr_codestorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexternorequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codestorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallotehistorico where materiallotehistorico.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallotehistorico.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codaberturainicial = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codfechado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codaberto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from responsavelcertificado where responsavelcertificado.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela responsavelcertificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codelegibilidade = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codsolicitadotiss = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codcoletar = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoquematerial where transfestoquematerial.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoquematerial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoque where transfestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaodadosbrutos where examerequisicaodadosbrutos.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaodadosbrutos.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaoincerteza where examerequisicaoincerteza.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoincerteza.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setoresnaoconformidadeusuario where setoresnaoconformidadeusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setoresnaoconformidadeusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setoresnaoconformidade where setoresnaoconformidade.usr_codresponsavelsetor = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setoresnaoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtransportechegada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtransportesaida = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lotefilial where lotefilial.usr_codrecebeu = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lotefilial where lotefilial.usr_codenviou = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logoffline where logoffline.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logoffline.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariologin where usuariologin.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariologin.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from acoesnaoconformidade where acoesnaoconformidade.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela acoesnaoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamentolog where orcamentolog.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamentolog.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamento where orcamento.usr_codaprovado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codconclusao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codanalise = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codregistro = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexterno where labexterno.usr_codconferir = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from banhomariatemperatura where banhomariatemperatura.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela banhomariatemperatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from banhomaria where banhomaria.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela banhomaria.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from filiais_postocoleta where filiais_postocoleta.usr_codcompras = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiais_postocoleta.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from filiais_postocoleta where filiais_postocoleta.usr_codestoque = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiais_postocoleta.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaolaminas where examerequisicaolaminas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaolaminas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codhorarioanexado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codbloqueado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codremovido = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohash where examerequisicaohash.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohash.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codfinalizado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codemcoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codremarcado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaolog where requisicaolog.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolog.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenioshistoricocota where convenioshistoricocota.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenioshistoricocota.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaotrocas where examerequisicaotrocas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaotrocas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtrocalayout = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codalteracaopreco = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariocompromisso where usuariocompromisso.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariocompromisso.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codsituacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrassenharequisicao where contrassenharequisicao.usr_codgerada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrassenharequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrassenharequisicao where contrassenharequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrassenharequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codentrega = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenioignorarecebimento where convenioignorarecebimento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenioignorarecebimento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosetor where examerequisicaosetor.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosetor.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codimpressaocarteira = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialenviado where materialenviado.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialenviado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialidentificado where materialidentificado.usr_codretorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialidentificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialidentificado where materialidentificado.usr_codenvio = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialidentificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteapoio where loteapoio.usr_codrecebeucaixa = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteapoio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosoroteca where examerequisicaosoroteca.usr_coddescarte = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosoroteca where examerequisicaosoroteca.usr_codsoroteca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codguiarepasse = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codrecoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codfaturarepasse = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcomissao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from montagemkit where montagemkit.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela montagemkit.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoque where transfestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamento where orcamento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from estoquemanual where estoquemanual.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela estoquemanual.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codalmoxarife = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codautorizafinanceira = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaestoque where conferenciaestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codconciliacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaentrada where conferenciaentrada.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaentrada.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaentrada where conferenciaentrada.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaentrada.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codexclusao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codcomissao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codautorizacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from cotacao where cotacao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela cotacao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from material where material.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela material.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codprotestocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcartoriocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codavisocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codrepeticao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codalteracao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codguia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosituacoes where examerequisicaosituacoes.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosituacoes.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from exames where exames.usr_codassinaweb = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exames.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codexcluido = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codexcluida = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenios where convenios.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenios.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codreimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from geladeirastemperaturas where geladeirastemperaturas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela geladeirastemperaturas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from geladeiras where geladeiras.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela geladeiras.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariofilial where usuariofilial.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariofilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codcancelada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from baixa where baixa.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela baixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from baixa where baixa.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela baixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctocaixa where lanctocaixa.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctocaixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaocid10 where requisicaocid10.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaocid10.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmaterialsetor = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codloteexterno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codenvio = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codcriacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from log where log.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela log.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariomensagem where usuariomensagem.usr_codorigem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariomensagem where usuariomensagem.usr_coddestino = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conveniomensagem where conveniomensagem.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conveniomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaorecipiente where examerequisicaorecipiente.usr_codtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaorecipiente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codetqtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codetqcoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteapoio where loteapoio.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteapoio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codconferencia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrasenha where contrasenha.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrasenha.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codnaofaturar = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaousuario where requisicaousuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaousuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codabertura = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codcortesia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmapa = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from interfaceexamerequisicao where interfaceexamerequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela interfaceexamerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuarioparametro where usuarioparametro.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuarioparametro.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctocaixa where lanctocaixa.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctocaixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codentrega = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codfatura = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmaterial = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_coddigitador = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codassina = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuarioacesso where usuarioacesso.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuarioacesso.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setores where setores.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setores.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; select count(*) into numrows from tipousuario where new.tpu_codigo = tipousuario.tpu_codigo; tmp:=''tipousuario|''; tmp:=tmp || ''tpu_codigo='' || new.tpu_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.tpu_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela tipousuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_usuario after update on usuario for each row execute procedure fn_tu_usuario(); create sequence preagendamentoevento_seguence; create sequence preagendamentoimagem_seguence; select criasequencia('preagendamentoevento'); select criasequencia('preagendamentoimagem'); insert into atualizacoes(atu_nome) values ('v21010007_220121.sql'); create index xdataenvio on logsms ( sms_dataenvio ); create index xdataenviosituacao on logsms ( sms_datahora, sms_situacao ); insert into atualizacoes(atu_nome) values ('v21010008_250121.sql'); create or replace function validarxml(varchar) returns boolean as $$ declare xml alias for $1; begin return length(trim(coalesce(xml, ''))) > 0 and length(trim(pegartag(xml, 'hpardini'))) > 0; exception when others then return false; end; $$ language plpgsql; create or replace function pegartag(varchar, varchar) returns varchar as $$ declare xml alias for $1; tag alias for $2; tmp varchar; posinicial integer; posfinal integer; tagfinal varchar; begin tmp = ''; posfinal = -1; posinicial = -1; if length(trim(xml)) > 0 then posinicial = strpos(xml, '<' || tag || '>'); end if; tagfinal = ''; if length(trim(xml)) > 0 then posfinal = strpos(xml, tagfinal); end if; if (posinicial > -1 and posfinal > 0 and posfinal > posinicial) then tmp = substring(xml, posinicial, (posfinal + length(tagfinal)) - posinicial); end if; return tmp; exception when others then return ''; end; $$ language plpgsql; create or replace function pegarvalortag(varchar, varchar) returns varchar as $$ declare xml alias for $1; tag alias for $2; tmp varchar; posinicial integer; posfinal integer; tagfinal varchar; taginicial varchar; begin tmp = ''; posfinal = -1; posinicial = -1; taginicial = '<' || tag || '>'; tagfinal = ''; if length(trim(xml)) > 0 then posinicial = strpos(xml, taginicial); end if; if length(trim(xml)) > 0 then posfinal = strpos(xml, tagfinal); end if; if (posinicial > -1 and posfinal > 0 and posfinal > posinicial) then tmp = substring(xml, posinicial + length(taginicial), posfinal - (length(taginicial) + posinicial)); end if; return tmp; exception when others then return ''; end; $$ language plpgsql; create or replace function integrarfilial(integer) returns boolean as $$ declare filial alias for $1; integrar boolean = false; begin select coalesce(fil_integrar, false) into integrar from filiais_postocoleta where fil_codigo = filial; if not found then integrar = false; end if; return integrar; end; $$ language plpgsql; create or replace function selecionarfilial() returns integer as $$ declare parametro varchar(1); retorno integer; filiaisintegracao varchar; filiaisintegracaoarray int[]; begin retorno = 1; select coalesce(par_tipointegracao, 'N') into parametro from parametros; if parametro = 'N' then select fil_codigo into retorno from filiais_postocoleta where fil_tipobase = 'C' order by fil_codigo limit 1; elsif parametro = 'F' or parametro = 'W' then select coalesce(par_filiaisintegracao, '') into filiaisintegracao from parametros; if length(trim(filiaisintegracao)) = 0 then select fil_codigo into retorno from filiais_postocoleta where fil_tipobase = 'C' order by fil_codigo limit 1; else filiaisintegracaoarray = string_to_array((xpath('/filiaisIntegracao/text()',filiaisintegracao::xml))[1]::varchar, ',')::integer[]; select fil_codigo into retorno from filiais_postocoleta where fil_tipobase = 'C' and fil_codigo = any(filiaisintegracaoarray) order by fil_codigo limit 1; end if; else --matriz select coalesce(par_copialabexterno, '') into filiaisintegracao from parametros; if length(trim(filiaisintegracao)) = 0 then select fil_codigo into retorno from filiais_postocoleta where fil_tipobase = 'C' order by fil_codigo limit 1; else filiaisintegracaoarray = string_to_array((xpath('/filiais/text()',filiaisintegracao::xml))[1]::varchar, ',')::integer[]; if (filiaisintegracaoarray is null) then select fil_codigo into retorno from filiais_postocoleta where fil_tipobase = 'C' order by fil_codigo limit 1; else select fil_codigo into retorno from filiais_postocoleta where fil_tipobase = 'C' and fil_codigo = any(filiaisintegracaoarray) order by fil_codigo limit 1; end if; end if; end if; return retorno; end; $$ language plpgsql; /*create or replace function selecionarfilialporcnpj(varchar) returns integer as $$ declare vcnpj alias for $1; cnpj varchar; parametro varchar(1); retorno integer; filiaisintegracao varchar; filiaisintegracaoarray int[]; begin retorno = 1; --limpa o cnpj cnpj = regexp_replace(vcnpj, '[^0-9]+', '', 'g'); --recoloca os pontos corretamente cnpj = regexp_replace(LPAD(cnpj, 14),'([0-9]{2})([0-9]{3})([0-9]{3})([0-9]{4})','\1.\2.\3/\4-'); select coalesce(par_tipointegracao, 'N') into parametro from parametros; if parametro = 'N' then select fil_codigo into retorno from filiais_postocoleta where fil_tipobase = 'C' and fil_cnpj = cnpj order by fil_codigo limit 1; elsif parametro = 'F' or parametro = 'W' then select coalesce(par_filiaisintegracao, '') into filiaisintegracao from parametros; if length(trim(filiaisintegracao)) = 0 then select fil_codigo into retorno from filiais_postocoleta where fil_tipobase = 'C' and fil_cnpj = cnpj order by fil_codigo limit 1; else filiaisintegracaoarray = string_to_array((xpath('/filiaisIntegracao/text()',filiaisintegracao::xml))[1]::varchar, ',')::integer[]; select fil_codigo into retorno from filiais_postocoleta where fil_tipobase = 'C' and fil_cnpj = cnpj and fil_codigo = any(filiaisintegracaoarray) order by fil_codigo limit 1; end if; else --matriz select coalesce(par_copialabexterno, '') into filiaisintegracao from parametros; if length(trim(filiaisintegracao)) = 0 or length(pegarvalortag(trim(filiaisintegracao), 'filiais')) = 0 then select fil_codigo into retorno from filiais_postocoleta where fil_tipobase = 'C' and fil_cnpj = cnpj order by fil_codigo limit 1; else filiaisintegracaoarray = string_to_array((xpath('/filiais/text()',filiaisintegracao::xml))[1]::varchar, ',')::integer[]; select fil_codigo into retorno from filiais_postocoleta where fil_tipobase = 'C' and fil_cnpj = cnpj and fil_codigo = any(filiaisintegracaoarray) order by fil_codigo limit 1; end if; end if; return retorno; end; $$ language plpgsql; */ insert into atualizacoes(atu_nome) values ('v21010009_270121.sql'); alter table configuracaoweb add cwe_apresentarpolitica boolean default false, add cwe_textopolitica text, add cwe_mensagempolitica varchar(500), add cwe_tituloocultarpolitica varchar(20), add cwe_titulolerpolitica varchar(20); insert into atualizacoes(atu_nome) values ('v21010010_280121.sql'); alter table configuracaoweb add cwe_versaotextopolitica varchar(6); create table historicopoliticaweb ( cwe_baseweb varchar(10) not null, hpw_versao varchar(6) not null, hpw_datahora timestamp default current_timestamp, hpw_textopolitica text, usr_codigo varchar(20) ); create unique index xpkhistoricopoliticaweb on historicopoliticaweb ( cwe_baseweb, hpw_versao ); create index xif1historicopoliticaweb on historicopoliticaweb ( cwe_baseweb ); create index xif2historicopoliticaweb on historicopoliticaweb ( usr_codigo ); alter table historicopoliticaweb add primary key (cwe_baseweb, hpw_versao); drop function fn_td_configuracaoweb() cascade; create function fn_td_configuracaoweb() returns opaque as ' declare numrows integer; begin delete from historicopoliticaweb where historicopoliticaweb.cwe_baseweb = old.cwe_baseweb; delete from satisfacaoweb where satisfacaoweb.cwe_baseweb = old.cwe_baseweb; return old; end;' language 'plpgsql'; create trigger td_configuracaoweb after delete on configuracaoweb for each row execute procedure fn_td_configuracaoweb(); drop function fn_tu_configuracaoweb() cascade; create function fn_tu_configuracaoweb() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.cwe_baseweb <> new.cwe_baseweb) then select count(*) from historicopoliticaweb where historicopoliticaweb.cwe_baseweb = old.cwe_baseweb into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela historicopoliticaweb.''; end if; end if; if (old.cwe_baseweb <> new.cwe_baseweb) then select count(*) from satisfacaoweb where satisfacaoweb.cwe_baseweb = old.cwe_baseweb into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela satisfacaoweb.''; end if; end if; return old; end;' language 'plpgsql'; create trigger tu_configuracaoweb after update on configuracaoweb for each row execute procedure fn_tu_configuracaoweb(); --drop function fn_ti_historicopoliticaweb() cascade; create function fn_ti_historicopoliticaweb() 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 configuracaoweb where new.cwe_baseweb = configuracaoweb.cwe_baseweb; tmp:=''configuracaoweb|''; tmp:=tmp || ''cwe_baseweb='' || new.cwe_baseweb || ''|''; 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 configuracaoweb. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_historicopoliticaweb after insert on historicopoliticaweb for each row execute procedure fn_ti_historicopoliticaweb(); --drop function fn_tu_historicopoliticaweb() cascade; create function fn_tu_historicopoliticaweb() 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 configuracaoweb where new.cwe_baseweb = configuracaoweb.cwe_baseweb; tmp:=''configuracaoweb|''; tmp:=tmp || ''cwe_baseweb='' || new.cwe_baseweb || ''|''; 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 configuracaoweb. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_historicopoliticaweb after update on historicopoliticaweb for each row execute procedure fn_tu_historicopoliticaweb(); drop function fn_td_usuario() cascade; create function fn_td_usuario() returns opaque as ' declare numrows integer; begin select count(*) into numrows from historicopoliticaweb where historicopoliticaweb.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela historicopoliticaweb.''; end if; select count(*) into numrows from preagendamentoevento where preagendamentoevento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamentoevento.''; end if; select count(*) into numrows from labexternologintegracao where labexternologintegracao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexternologintegracao.''; end if; select count(*) into numrows from labexternoversaotermo where labexternoversaotermo.usr_codaceite = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexternoversaotermo.''; end if; select count(*) into numrows from preagendamento where preagendamento.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamento.''; end if; select count(*) into numrows from preagendamento where preagendamento.usr_codagendou = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamento.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_coddialsist = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from integracaosave where integracaosave.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela integracaosave.''; end if; select count(*) into numrows from interfaceexamereagente where interfaceexamereagente.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela interfaceexamereagente.''; end if; select count(*) into numrows from examerequisicaohistoricoentrega where examerequisicaohistoricoentrega.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricoentrega.''; end if; select count(*) into numrows from requisicaopaginasimpressas where requisicaopaginasimpressas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaopaginasimpressas.''; end if; select count(*) into numrows from tabelaprecoexamesusuario where tabelaprecoexamesusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela tabelaprecoexamesusuario.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codenvioemail = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from materialusuario where materialusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialusuario.''; end if; select count(*) into numrows from logids where logids.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logids.''; end if; select count(*) into numrows from logvalidalotematerial where logvalidalotematerial.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logvalidalotematerial.''; end if; select count(*) into numrows from material where material.usr_codavisolote = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela material.''; end if; delete from usuariosenhas where usuariosenhas.usr_codigo = old.usr_codigo; select count(*) into numrows from pacienteimagens where pacienteimagens.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pacienteimagens.''; end if; select count(*) into numrows from requisicaoimagens where requisicaoimagens.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoimagens.''; end if; select count(*) into numrows from orcamentoconvenio where orcamentoconvenio.usr_coddesconto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamentoconvenio.''; end if; select count(*) into numrows from requisicao where requisicao.usr_coddesconto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicaoetiquetas where examerequisicaoetiquetas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaoetiquetas.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codduplaconferencia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteexternorequisicao where loteexternorequisicao.usr_codestorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexternorequisicao.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codestorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from materiallotehistorico where materiallotehistorico.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallotehistorico.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codaberturainicial = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codfechado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codaberto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; delete from responsavelcertificado where responsavelcertificado.usr_codigo = old.usr_codigo; select count(*) into numrows from requisicao where requisicao.usr_codelegibilidade = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codsolicitadotiss = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codcoletar = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from transfestoquematerial where transfestoquematerial.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoquematerial.''; end if; select count(*) into numrows from transfestoque where transfestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoque.''; end if; select count(*) into numrows from examerequisicaodadosbrutos where examerequisicaodadosbrutos.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaodadosbrutos.''; end if; select count(*) into numrows from examerequisicaoincerteza where examerequisicaoincerteza.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaoincerteza.''; end if; select count(*) into numrows from setoresnaoconformidadeusuario where setoresnaoconformidadeusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setoresnaoconformidadeusuario.''; end if; select count(*) into numrows from setoresnaoconformidade where setoresnaoconformidade.usr_codresponsavelsetor = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setoresnaoconformidade.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtransportechegada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtransportesaida = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from lotefilial where lotefilial.usr_codrecebeu = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilial.''; end if; select count(*) into numrows from lotefilial where lotefilial.usr_codenviou = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilial.''; end if; select count(*) into numrows from logoffline where logoffline.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logoffline.''; end if; select count(*) into numrows from usuariologin where usuariologin.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuariologin.''; end if; select count(*) into numrows from acoesnaoconformidade where acoesnaoconformidade.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela acoesnaoconformidade.''; end if; select count(*) into numrows from orcamentolog where orcamentolog.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamentolog.''; end if; select count(*) into numrows from orcamento where orcamento.usr_codaprovado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamento.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codconclusao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codanalise = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codregistro = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from labexterno where labexterno.usr_codconferir = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexterno.''; end if; select count(*) into numrows from banhomariatemperatura where banhomariatemperatura.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela banhomariatemperatura.''; end if; select count(*) into numrows from banhomaria where banhomaria.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela banhomaria.''; end if; select count(*) into numrows from filiais_postocoleta where filiais_postocoleta.usr_codcompras = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiais_postocoleta.''; end if; select count(*) into numrows from filiais_postocoleta where filiais_postocoleta.usr_codestoque = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiais_postocoleta.''; end if; select count(*) into numrows from examerequisicaolaminas where examerequisicaolaminas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaolaminas.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codhorarioanexado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codbloqueado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codremovido = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from examerequisicaohash where examerequisicaohash.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohash.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codfinalizado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codemcoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codremarcado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from requisicaolog where requisicaolog.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolog.''; end if; select count(*) into numrows from convenioshistoricocota where convenioshistoricocota.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenioshistoricocota.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from examerequisicaotrocas where examerequisicaotrocas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaotrocas.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtrocalayout = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codalteracaopreco = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; delete from usuariocompromisso where usuariocompromisso.usr_codigo = old.usr_codigo; select count(*) into numrows from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codsituacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; select count(*) into numrows from contrassenharequisicao where contrassenharequisicao.usr_codgerada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrassenharequisicao.''; end if; select count(*) into numrows from contrassenharequisicao where contrassenharequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrassenharequisicao.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codentrega = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from convenioignorarecebimento where convenioignorarecebimento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenioignorarecebimento.''; end if; select count(*) into numrows from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; select count(*) into numrows from examerequisicaosetor where examerequisicaosetor.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosetor.''; end if; select count(*) into numrows from paciente where paciente.usr_codimpressaocarteira = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; select count(*) into numrows from materialenviado where materialenviado.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialenviado.''; end if; select count(*) into numrows from materialidentificado where materialidentificado.usr_codretorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialidentificado.''; end if; select count(*) into numrows from materialidentificado where materialidentificado.usr_codenvio = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialidentificado.''; end if; select count(*) into numrows from loteapoio where loteapoio.usr_codrecebeucaixa = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteapoio.''; end if; select count(*) into numrows from examerequisicaosoroteca where examerequisicaosoroteca.usr_coddescarte = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosoroteca.''; end if; select count(*) into numrows from examerequisicaosoroteca where examerequisicaosoroteca.usr_codsoroteca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosoroteca.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codguiarepasse = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codrecoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codfaturarepasse = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcomissao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from montagemkit where montagemkit.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela montagemkit.''; end if; select count(*) into numrows from transfestoque where transfestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoque.''; end if; select count(*) into numrows from orcamento where orcamento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamento.''; end if; select count(*) into numrows from estoquemanual where estoquemanual.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela estoquemanual.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codalmoxarife = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codautorizafinanceira = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from conferenciaestoque where conferenciaestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codconciliacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from conferenciaentrada where conferenciaentrada.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaentrada.''; end if; select count(*) into numrows from conferenciaentrada where conferenciaentrada.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaentrada.''; end if; select count(*) into numrows from pedido where pedido.usr_codexclusao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from fatura where fatura.usr_codcomissao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from pedido where pedido.usr_codautorizacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from pedido where pedido.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from cotacao where cotacao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela cotacao.''; end if; select count(*) into numrows from material where material.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela material.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codprotestocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcartoriocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codavisocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codrepeticao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from paciente where paciente.usr_codalteracao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codguia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicaosituacoes where examerequisicaosituacoes.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosituacoes.''; end if; select count(*) into numrows from exames where exames.usr_codassinaweb = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela exames.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codexcluido = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codexcluida = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from fatura where fatura.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from convenios where convenios.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenios.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codreimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from geladeirastemperaturas where geladeirastemperaturas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela geladeirastemperaturas.''; end if; select count(*) into numrows from geladeiras where geladeiras.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela geladeiras.''; end if; delete from usuariofilial where usuariofilial.usr_codigo = old.usr_codigo; select count(*) into numrows from notafiscal where notafiscal.usr_codimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codcancelada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from baixa where baixa.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela baixa.''; end if; select count(*) into numrows from baixa where baixa.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela baixa.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from lanctocaixa where lanctocaixa.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctocaixa.''; end if; select count(*) into numrows from requisicaocid10 where requisicaocid10.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaocid10.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmaterialsetor = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codloteexterno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codenvio = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codcriacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from log where log.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela log.''; end if; select count(*) into numrows from usuariomensagem where usuariomensagem.usr_codorigem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuariomensagem.''; end if; delete from usuariomensagem where usuariomensagem.usr_coddestino = old.usr_codigo; select count(*) into numrows from conveniomensagem where conveniomensagem.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conveniomensagem.''; end if; select count(*) into numrows from examerequisicaorecipiente where examerequisicaorecipiente.usr_codtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaorecipiente.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codetqtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codetqcoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteapoio where loteapoio.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteapoio.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from fatura where fatura.usr_codconferencia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from fatura where fatura.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from contrasenha where contrasenha.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrasenha.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codnaofaturar = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicaousuario where requisicaousuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaousuario.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codabertura = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codcortesia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmapa = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from interfaceexamerequisicao where interfaceexamerequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela interfaceexamerequisicao.''; end if; select count(*) into numrows from usuarioparametro where usuarioparametro.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuarioparametro.''; end if; select count(*) into numrows from lanctocaixa where lanctocaixa.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctocaixa.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codentrega = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codfatura = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmaterial = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_coddigitador = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codassina = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; delete from usuarioacesso where usuarioacesso.usr_codigo = old.usr_codigo; select count(*) into numrows from setores where setores.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setores.''; end if; select count(*) into numrows from paciente where paciente.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; return old; end;' language 'plpgsql'; create trigger td_usuario after delete on usuario for each row execute procedure fn_td_usuario(); drop function fn_ti_usuario() cascade; create function fn_ti_usuario() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from tipousuario where new.tpu_codigo = tipousuario.tpu_codigo; tmp:=''tipousuario|''; tmp:=tmp || ''tpu_codigo='' || new.tpu_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.tpu_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela tipousuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_usuario after insert on usuario for each row execute procedure fn_ti_usuario(); drop function fn_tu_usuario() cascade; create function fn_tu_usuario() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.usr_codigo <> new.usr_codigo) then select count(*) from historicopoliticaweb where historicopoliticaweb.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela historicopoliticaweb.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from preagendamentoevento where preagendamentoevento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamentoevento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexternologintegracao where labexternologintegracao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternologintegracao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexternoversaotermo where labexternoversaotermo.usr_codaceite = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternoversaotermo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from preagendamento where preagendamento.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from preagendamento where preagendamento.usr_codagendou = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_coddialsist = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from integracaosave where integracaosave.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela integracaosave.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from interfaceexamereagente where interfaceexamereagente.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela interfaceexamereagente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricoentrega where examerequisicaohistoricoentrega.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricoentrega.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaopaginasimpressas where requisicaopaginasimpressas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaopaginasimpressas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from tabelaprecoexamesusuario where tabelaprecoexamesusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela tabelaprecoexamesusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codenvioemail = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialusuario where materialusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logids where logids.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logids.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logvalidalotematerial where logvalidalotematerial.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logvalidalotematerial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from material where material.usr_codavisolote = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela material.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariosenhas where usuariosenhas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariosenhas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pacienteimagens where pacienteimagens.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pacienteimagens.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoimagens where requisicaoimagens.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoimagens.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamentoconvenio where orcamentoconvenio.usr_coddesconto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamentoconvenio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_coddesconto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaoetiquetas where examerequisicaoetiquetas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoetiquetas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codduplaconferencia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexternorequisicao where loteexternorequisicao.usr_codestorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexternorequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codestorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallotehistorico where materiallotehistorico.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallotehistorico.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codaberturainicial = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codfechado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codaberto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from responsavelcertificado where responsavelcertificado.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela responsavelcertificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codelegibilidade = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codsolicitadotiss = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codcoletar = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoquematerial where transfestoquematerial.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoquematerial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoque where transfestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaodadosbrutos where examerequisicaodadosbrutos.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaodadosbrutos.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaoincerteza where examerequisicaoincerteza.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoincerteza.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setoresnaoconformidadeusuario where setoresnaoconformidadeusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setoresnaoconformidadeusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setoresnaoconformidade where setoresnaoconformidade.usr_codresponsavelsetor = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setoresnaoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtransportechegada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtransportesaida = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lotefilial where lotefilial.usr_codrecebeu = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lotefilial where lotefilial.usr_codenviou = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logoffline where logoffline.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logoffline.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariologin where usuariologin.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariologin.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from acoesnaoconformidade where acoesnaoconformidade.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela acoesnaoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamentolog where orcamentolog.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamentolog.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamento where orcamento.usr_codaprovado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codconclusao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codanalise = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codregistro = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexterno where labexterno.usr_codconferir = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from banhomariatemperatura where banhomariatemperatura.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela banhomariatemperatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from banhomaria where banhomaria.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela banhomaria.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from filiais_postocoleta where filiais_postocoleta.usr_codcompras = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiais_postocoleta.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from filiais_postocoleta where filiais_postocoleta.usr_codestoque = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiais_postocoleta.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaolaminas where examerequisicaolaminas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaolaminas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codhorarioanexado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codbloqueado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codremovido = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohash where examerequisicaohash.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohash.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codfinalizado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codemcoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codremarcado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaolog where requisicaolog.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolog.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenioshistoricocota where convenioshistoricocota.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenioshistoricocota.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaotrocas where examerequisicaotrocas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaotrocas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtrocalayout = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codalteracaopreco = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariocompromisso where usuariocompromisso.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariocompromisso.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codsituacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrassenharequisicao where contrassenharequisicao.usr_codgerada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrassenharequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrassenharequisicao where contrassenharequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrassenharequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codentrega = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenioignorarecebimento where convenioignorarecebimento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenioignorarecebimento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosetor where examerequisicaosetor.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosetor.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codimpressaocarteira = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialenviado where materialenviado.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialenviado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialidentificado where materialidentificado.usr_codretorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialidentificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialidentificado where materialidentificado.usr_codenvio = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialidentificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteapoio where loteapoio.usr_codrecebeucaixa = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteapoio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosoroteca where examerequisicaosoroteca.usr_coddescarte = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosoroteca where examerequisicaosoroteca.usr_codsoroteca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codguiarepasse = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codrecoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codfaturarepasse = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcomissao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from montagemkit where montagemkit.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela montagemkit.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoque where transfestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamento where orcamento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from estoquemanual where estoquemanual.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela estoquemanual.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codalmoxarife = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codautorizafinanceira = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaestoque where conferenciaestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codconciliacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaentrada where conferenciaentrada.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaentrada.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaentrada where conferenciaentrada.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaentrada.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codexclusao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codcomissao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codautorizacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from cotacao where cotacao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela cotacao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from material where material.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela material.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codprotestocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcartoriocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codavisocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codrepeticao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codalteracao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codguia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosituacoes where examerequisicaosituacoes.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosituacoes.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from exames where exames.usr_codassinaweb = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exames.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codexcluido = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codexcluida = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenios where convenios.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenios.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codreimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from geladeirastemperaturas where geladeirastemperaturas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela geladeirastemperaturas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from geladeiras where geladeiras.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela geladeiras.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariofilial where usuariofilial.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariofilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codcancelada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from baixa where baixa.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela baixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from baixa where baixa.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela baixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctocaixa where lanctocaixa.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctocaixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaocid10 where requisicaocid10.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaocid10.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmaterialsetor = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codloteexterno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codenvio = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codcriacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from log where log.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela log.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariomensagem where usuariomensagem.usr_codorigem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariomensagem where usuariomensagem.usr_coddestino = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conveniomensagem where conveniomensagem.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conveniomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaorecipiente where examerequisicaorecipiente.usr_codtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaorecipiente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codetqtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codetqcoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteapoio where loteapoio.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteapoio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codconferencia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrasenha where contrasenha.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrasenha.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codnaofaturar = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaousuario where requisicaousuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaousuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codabertura = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codcortesia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmapa = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from interfaceexamerequisicao where interfaceexamerequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela interfaceexamerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuarioparametro where usuarioparametro.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuarioparametro.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctocaixa where lanctocaixa.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctocaixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codentrega = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codfatura = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmaterial = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_coddigitador = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codassina = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuarioacesso where usuarioacesso.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuarioacesso.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setores where setores.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setores.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; select count(*) into numrows from tipousuario where new.tpu_codigo = tipousuario.tpu_codigo; tmp:=''tipousuario|''; tmp:=tmp || ''tpu_codigo='' || new.tpu_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.tpu_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela tipousuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_usuario after update on usuario for each row execute procedure fn_tu_usuario(); create sequence historicotextopolitica_sequence; insert into atualizacoes(atu_nome) values ('v21010011_290121.sql'); alter table parametros add par_chavecripto varchar(15); insert into atualizacoes(atu_nome) values ('v21010012_080221.sql');