CREATE TABLE system_group( 
      id  integer generated by default as identity primary key     NOT NULL , 
      name blob sub_type 1    NOT NULL , 
 PRIMARY KEY (id)); 

 CREATE TABLE system_group_program( 
      id  integer generated by default as identity primary key     NOT NULL , 
      system_group_id integer    NOT NULL , 
      system_program_id integer    NOT NULL , 
 PRIMARY KEY (id)); 

 CREATE TABLE system_preference( 
      id blob sub_type 1    NOT NULL , 
      preference blob sub_type 1    NOT NULL ); 

 CREATE TABLE system_program( 
      id  integer generated by default as identity primary key     NOT NULL , 
      name blob sub_type 1    NOT NULL , 
      controller blob sub_type 1    NOT NULL , 
 PRIMARY KEY (id)); 

 CREATE TABLE system_unit( 
      id  integer generated by default as identity primary key     NOT NULL , 
      name blob sub_type 1    NOT NULL , 
 PRIMARY KEY (id)); 

 CREATE TABLE system_user_group( 
      id  integer generated by default as identity primary key     NOT NULL , 
      system_user_id integer    NOT NULL , 
      system_group_id integer    NOT NULL , 
 PRIMARY KEY (id)); 

 CREATE TABLE system_user_program( 
      id  integer generated by default as identity primary key     NOT NULL , 
      system_user_id integer    NOT NULL , 
      system_program_id integer    NOT NULL , 
 PRIMARY KEY (id)); 

 CREATE TABLE system_users( 
      id  integer generated by default as identity primary key     NOT NULL , 
      name blob sub_type 1    NOT NULL , 
      login blob sub_type 1    NOT NULL , 
      password blob sub_type 1    NOT NULL , 
      email blob sub_type 1   , 
      frontpage_id integer   , 
      system_unit_id integer   , 
      active char  (1)   , 
 PRIMARY KEY (id)); 

 CREATE TABLE system_user_unit( 
      id  integer generated by default as identity primary key     NOT NULL , 
      system_user_id integer    NOT NULL , 
      system_unit_id integer    NOT NULL , 
 PRIMARY KEY (id)); 

 CREATE TABLE tabcadaplicacao( 
      id  integer generated by default as identity primary key     NOT NULL , 
      CODIGO integer   , 
      NUMFAI float  (10,2)   , 
      PAJIFER float  (10,2)   , 
      PPOTASSIO integer  (10,2)   , 
 PRIMARY KEY (id)); 

 CREATE TABLE tabcadbanco( 
      NUMBAN  integer generated by default as identity primary key     NOT NULL , 
      NOMBAN char  (50)   , 
 PRIMARY KEY (NUMBAN)); 

 CREATE TABLE tabcadcentrodecustos( 
      codcentrodecustos  integer generated by default as identity primary key     NOT NULL , 
      nomecentrodecustos varchar  (255)   , 
      situacao varchar  (255)   , 
      codemp integer  (11)   , 
      coduser integer  (11)   , 
 PRIMARY KEY (codcentrodecustos)); 

 CREATE TABLE tabcadcfop( 
      NATOPE  integer generated by default as identity primary key     NOT NULL , 
      CFOP char  (5)   , 
      NOMCFO char  (27)   , 
      ESTOQUE integer  (1)   , 
 PRIMARY KEY (NATOPE)); 

 CREATE TABLE tabcadcidade( 
      codcidade  integer generated by default as identity primary key     NOT NULL , 
      cidade varchar  (255)   , 
      uf char  (2)   , 
 PRIMARY KEY (codcidade)); 

 CREATE TABLE tabcadcliente( 
      NUMCLI  integer generated by default as identity primary key     NOT NULL , 
      DATCAD date   , 
      NOMCLI char  (59)   , 
      ENDCLI char  (40)   , 
      NUMCID integer  (4)   , 
      NUMCEP char  (9)   , 
      SIGEST char  (2)   , 
      NUMTEL char  (20)   , 
      NUMFAX char  (20)   , 
      EMAIL char  (50)   , 
      NOMCTT char  (59)   , 
      CGCCPF char  (20)   , 
      IERG char  (20)   , 
      NUMCOND integer  (4)   , 
      ENDCOB char  (40)   , 
      CIDCOB integer  (4)   , 
      CEPCOB char  (9)   , 
      SIGCOB char  (2)   , 
      TELCOB char  (15)   , 
      VLRUNI float  (9,2)   , 
      TIPPRECO char  (1)   , 
      PAGAFRETE char  (1)   , 
      NOMFAN char  (40)   , 
      NOMPRO char  (58)   , 
      NOMMOT char  (58)   , 
      OBS001 char  (68)   , 
      OBS002 char  (73)   , 
      SITCLI char  (1)   , 
      RCNOME1 char  (32)   , 
      RCFONE1 char  (20)   , 
      RCFALA1 char  (20)   , 
      RCNOME2 char  (32)   , 
      RCFONE2 char  (20)   , 
      RCFALA2 char  (20)   , 
      RCNOME3 char  (32)   , 
      RCFONE3 char  (20)   , 
      RCFALA3 char  (20)   , 
      RCNOME4 char  (32)   , 
      RCFONE4 char  (20)   , 
      RCFALA4 char  (20)   , 
      RCNOME5 char  (32)   , 
      RCFONE5 char  (20)   , 
      RCFALA5 char  (20)   , 
      RBNOME1 char  (32)   , 
      RBFONE1 char  (20)   , 
      RBFALA1 char  (20)   , 
      RBNOME2 char  (32)   , 
      RBFONE2 char  (20)   , 
      RBFALA2 char  (20)   , 
      RBNOME3 char  (32)   , 
      RBFONE3 char  (20)   , 
      RBFALA3 char  (20)   , 
      RBNOME4 char  (32)   , 
      RBFONE4 char  (20)   , 
      RBFALA4 char  (20)   , 
      RBNOME5 char  (32)   , 
      RBFONE5 char  (20)   , 
      RBFALA5 char  (20)   , 
      NUMCOB char  (9)   , 
      BAICOB char  (34)   , 
      CMPCOB char  (11)   , 
      FAZCOB char  (15)   , 
      CELCOB char  (13)   , 
      NUMERO char  (3)   , 
      CELULAR char  (12)   , 
      BAIRRO char  (34)   , 
      COMPL char  (11)   , 
      FAXCOB char  (15)   , 
      TIPOCLI char  (1)   , 
      FUNRURAL float  (9,2)   , 
      FUNDCITRUS float  (9,2)   , 
      BCOTIT char  (60)   , 
      BCODOC char  (18)   , 
      BCONUM char  (3)   , 
      BCOTIP integer  (1)   , 
      BCOAG char  (15)   , 
      BCOCON char  (15)   , 
      BCOOBS char  (60)   , 
      PESSOA integer  (1)   , 
      ULT_PEDIDO_TRANS integer   , 
 PRIMARY KEY (NUMCLI)); 

 CREATE TABLE tabcadenxerto( 
      codenxerto  integer generated by default as identity primary key     NOT NULL , 
      nomeenxerto varchar  (255)   , 
      situacao varchar  (255)   , 
      codemp integer  (11)   , 
      codext integer  (11)   , 
 PRIMARY KEY (codenxerto)); 

 CREATE TABLE tabcadfazenda( 
      codfaz  integer generated by default as identity primary key     NOT NULL , 
      codext integer  (11)   , 
      usualfaz varchar  (255)   , 
      situacao varchar  (255)   , 
      nomefaz varchar  (255)   , 
      codcidade integer  (11)   , 
      cep varchar  (255)   , 
      tel1 varchar  (255)   , 
      tel2 varchar  (255)   , 
      tel3 varchar  (255)   , 
      cnpj varchar  (255)   , 
      inscricao varchar  (255)   , 
      baixaestoque varchar  (255)   , 
      localestoque integer  (11)   , 
      notafiscal integer  (11)   , 
      totalm3 float  (10,2)   , 
      codempfaz integer  (11)   , 
      apestzero varchar  (255)   , 
      datadissidio date   , 
 PRIMARY KEY (codfaz)); 

 CREATE TABLE tabcadfornecedor( 
      codfornecedor  integer generated by default as identity primary key     NOT NULL , 
      nomefantasia varchar  (255)   , 
      nomefornecedor varchar  (255)   , 
      codemp integer  (11)   , 
      codext integer  (11)   , 
      cidade varchar  (255)   , 
      uf varchar  (255)   , 
      tel varchar  (255)   , 
      fax varchar  (255)   , 
      email varchar  (255)   , 
 PRIMARY KEY (codfornecedor)); 

 CREATE TABLE tabcadmaterial( 
      codmaterial  integer generated by default as identity primary key     NOT NULL , 
      codext integer  (11)   , 
      nomematerial varchar  (255)   , 
      unid varchar  (255)   , 
      codgrupo integer  (11)   , 
      manutencao varchar  (255)   , 
      valor float  (10)   , 
      aplicacao varchar  (255)   , 
      qtdeestoque float  (10)   , 
      codfabricante varchar  (255)   , 
      codnomefabricante integer  (11)   , 
      codclasse integer  (11)   , 
      codgrupoquimico integer  (11)   , 
      codativo integer  (11)   , 
      codpraga integer  (11)   , 
      situacao varchar  (255)   , 
      concentracao varchar  (255)   , 
      codtipoacao integer  (11)   , 
      codformulacao integer  (11)   , 
      linkbula varchar  (255)   , 
      codempmateriais integer  (11)   , 
      doseprod float  (10)   , 
      mlprod integer  (11)   , 
      mlm3 float  (10)   , 
      calcativom3 varchar  (255)   , 
      mlprodm3 float  (10)   , 
      limitarprod varchar  (255)   , 
      dosemax float  (10)   , 
      ltsbb integer  (11)   , 
      tipocalcdose float  (10)   , 
      tipocalc varchar  (255)   , 
      tipocalcltsbb integer  (11)   , 
      reentrada integer  (11)   , 
      registro varchar  (255)   , 
 PRIMARY KEY (codmaterial)); 

 CREATE TABLE tabcadmecanico( 
      codmec  integer generated by default as identity primary key     NOT NULL , 
      nomemec varchar  (255)   , 
      codemp integer  (11)   , 
      situacao varchar  (255)   , 
      codext integer  (11)   , 
 PRIMARY KEY (codmec)); 

 CREATE TABLE tabcadmotorista( 
      id  integer generated by default as identity primary key     NOT NULL , 
      NUMTRN integer  (4)   , 
      NUMMOT integer  (4)   , 
      NOMMOT char  (30)   , 
      PLACA char  (8)   , 
      UFPLACA char  (2)   , 
      MUNMOT char  (20)   , 
      SITMOT char  (1)   , 
      MUNIBGE char  (7)   , 
      NUMTEL char  (15)   , 
      CTe char  (1)   , 
 PRIMARY KEY (id)); 

 CREATE TABLE tabcadpatrimonio_tipo( 
      CODTPAT  integer generated by default as identity primary key     NOT NULL , 
      DESCTPAT char  (20)    NOT NULL , 
      SITTPAT char  (1)    NOT NULL , 
      NUMFRO char  (1)   , 
      NUMTRN char  (1)   , 
      ESTOQUE char  (1)   , 
      NUMFAZ char  (2)   , 
      CTHORI char  (1)   , 
 PRIMARY KEY (CODTPAT)); 

 CREATE TABLE tabcadPedidoTransporte( 
      Pedido  integer generated by default as identity primary key     NOT NULL , 
      PRCKM float  (10,2)   , 
      KMPEDIDO integer   , 
 PRIMARY KEY (Pedido)); 

 CREATE TABLE tabcadrequisicao( 
      id  integer generated by default as identity primary key     NOT NULL , 
      n_requisicao integer  (9)   , 
      dataehora timestamp    NOT NULL , 
      tabcadfazenda_id integer    NOT NULL , 
      tabcadfornecedor_id integer    NOT NULL , 
      tabcadpatrimonio_id integer   , 
      tabcadtransportadora_id integer  (6)   , 
      tabcadmotorista_id integer  (6)   , 
      tabcadmecanico_id integer  (11)   , 
      TIPPAT integer  (6)   , 
      cod_patrimonio integer  (6)   , 
      cod_frota integer  (6)   , 
      horimetro integer  (6)   , 
      estoque integer  (11)   , 
      documento varchar  (255)   , 
      observacao varchar  (255)   , 
      status varchar  (255)   , 
      valor_total_requisicao float  (10,2)   , 
      valor_desconto float  (10,2)   , 
      user_id integer    NOT NULL , 
 PRIMARY KEY (id)); 

 CREATE TABLE tabcadrequisicao_itens( 
      id  integer generated by default as identity primary key     NOT NULL , 
      tabcadrequisicao_id integer    NOT NULL , 
      tabcadmaterial_id integer    NOT NULL , 
      qtd integer  (6)    NOT NULL , 
      valor float  (10,2)    NOT NULL , 
 PRIMARY KEY (id)); 

 CREATE TABLE tabcadrequisicao_servico( 
      id  integer generated by default as identity primary key     NOT NULL , 
      tabcadservico_id integer    NOT NULL , 
      tabcadrequisicao_id integer    NOT NULL , 
      detalhes_servico blob sub_type 1   , 
      qtd integer  (6)    NOT NULL , 
      valor float  (10,2)    NOT NULL , 
 PRIMARY KEY (id)); 

 CREATE TABLE tabcadservico( 
      CODSER  integer generated by default as identity primary key     NOT NULL , 
      SERVICO char  (30)   , 
      VALOR float  (12,2)   , 
      SITUACAO char  (1)   , 
 PRIMARY KEY (CODSER)); 

 CREATE TABLE tabcadtransportadora( 
      NUMTRN  integer generated by default as identity primary key     NOT NULL , 
      NOMTRN char  (60)   , 
      NOMEND char  (30)   , 
      NUMCEP integer  (8)   , 
      NOMCID char  (20)   , 
      SIGEST char  (2)   , 
      NUMTEL char  (15)   , 
      NUMFAX char  (15)   , 
      CGCTRN char  (18)   , 
      INSEST char  (15)   , 
      NOMBAI char  (25)   , 
      DATFINI date   , 
      DATFFIN date   , 
      TITULAR char  (60)   , 
      BANCO char  (20)   , 
      AGENCIA char  (20)   , 
      CONTA char  (20)   , 
      CPF char  (20)   , 
      PFRETE char  (1)   , 
      NUMTEL2 char  (15)   , 
      DIGAG char  (2)   , 
      DIGCON char  (2)   , 
      NUMBAN char  (3)   , 
      PESSOA integer  (1)   , 
      BCONUM char  (3)   , 
      BCOTIP integer  (1)   , 
      BCOOBS char  (30)   , 
      RNTRC integer   , 
 PRIMARY KEY (NUMTRN)); 

 CREATE TABLE tabcadtrator( 
      codtrator  integer generated by default as identity primary key     NOT NULL , 
      situacao char  (10)    NOT NULL , 
      nometrator varchar  (255)    NOT NULL , 
      codtipopat integer  (6)    NOT NULL , 
      codfrotatrat integer  (6)   , 
      codpatrimonio integer  (6)    NOT NULL , 
 PRIMARY KEY (codtrator)); 

 CREATE TABLE tabcadvariedade( 
      codvari  integer generated by default as identity primary key     NOT NULL , 
      nomevari varchar  (255)   , 
      situacao varchar  (255)   , 
      codemp integer  (11)   , 
      codext integer  (11)   , 
 PRIMARY KEY (codvari)); 

 CREATE TABLE tabestoque( 
      codestoque  integer generated by default as identity primary key     NOT NULL , 
      nomeestoque varchar  (255)   , 
      codemp integer  (11)   , 
      situacao varchar  (255)   , 
      combustivel varchar  (255)   , 
      codext integer  (11)   , 
 PRIMARY KEY (codestoque)); 

 CREATE TABLE tabestoquefaz( 
      id  integer generated by default as identity primary key     NOT NULL , 
      codfaz integer  (11)   , 
      codestoque integer  (11)   , 
 PRIMARY KEY (id)); 

 CREATE TABLE tablantransporte( 
      id  integer generated by default as identity primary key     NOT NULL , 
      ChaveNotaOrigem integer   , 
      DataNota date   , 
      HoraNota time   , 
      Pedido integer   , 
      Pedido_PRCKM float  (10,2)   , 
      Pedido_KMPEDIDO integer   , 
      ValorPedagio float  (10,2)   , 
      NumeroNota integer   , 
      ValorNota float  (10,2)   , 
      Natureza varchar  (255)   , 
      UF integer   , 
      Placa char  (8)   , 
      Rntrc integer   , 
      cNF integer   , 
      Mod integer   , 
      Serie integer   , 
      cMunFG integer   , 
      modFrete integer   , 
      qVol integer   , 
      esp char   , 
      marca varchar  (255)   , 
      pesoL float  (10,3)   , 
      pesoB float  (10,3)   , 
      nLacre varchar  (255)   , 
      nFat integer   , 
      vOrig float  (10,2)   , 
      vDesc float  (10,2)   , 
      vLiq float  (10,2)   , 
      infCpl blob sub_type 1   , 
      nProt integer   , 
      ValorQuiloKM float  (10,2)   , 
      dosagem float  (10,2)   , 
      Valor90 float  (10,2)   , 
      Valor10 float  (10,2)   , 
      aplicacao integer   , 
      Transportadora_terceira integer   , 
      Motorista_terceiro integer   , 
      tablantransporteEmitente integer   , 
      tablantransporteDestinatario integer   , 
 PRIMARY KEY (id)); 

 CREATE TABLE tablantransporteDestinatario( 
      id  integer generated by default as identity primary key     NOT NULL , 
      CNPJ integer   , 
      XNome varchar  (255)   , 
      XFant varchar  (255)   , 
      xLgr varchar  (255)   , 
      nro char   , 
      xBairro varchar  (255)   , 
      cMun integer   , 
      xMun varchar  (255)   , 
      UF char  (2)   , 
      CEP integer   , 
      cPais integer   , 
      xPais varchar  (255)   , 
      fone integer   , 
      IndIEDest integer   , 
      IE integer   , 
 PRIMARY KEY (id)); 

 CREATE TABLE tablantransporteEmitente( 
      id  integer generated by default as identity primary key     NOT NULL , 
      CNPJ integer   , 
      xNome varchar  (255)   , 
      XFant varchar  (255)   , 
      xLgr varchar  (255)   , 
      nro char   , 
      xBairro varchar  (255)   , 
      cMun integer   , 
      xMun varchar  (255)   , 
      UF char  (2)   , 
      CEP integer  (8)   , 
      cPais integer   , 
      XPais varchar  (255)   , 
      fone integer   , 
      IE integer   , 
      CRT integer   , 
 PRIMARY KEY (id)); 

 CREATE TABLE tablantransporteProduto( 
      id  integer generated by default as identity primary key     NOT NULL , 
      id_tablantransporte integer    NOT NULL , 
      cProd integer   , 
      cEAN varchar  (255)   , 
      xProd varchar  (255)   , 
      NCM integer   , 
      EXTIPI integer   , 
      CFOP integer   , 
      uCom char   , 
      qCom float  (10,4)   , 
      vUnCom float  (10,10)   , 
      vProd float  (10,2)   , 
      cEANTrib varchar  (255)   , 
      uTrib char   , 
      qTrib float  (10,4)   , 
      vUnTrib float  (10,10)   , 
      indTot integer   , 
 PRIMARY KEY (id)); 

 CREATE TABLE tabmovestoque( 
      codmov  integer generated by default as identity primary key     NOT NULL , 
      tipomov varchar  (255)   , 
      transf varchar  (255)   , 
      manu varchar  (255)   , 
      codmanu integer  (11)   , 
      apto varchar  (255)   , 
      codcc integer  (11)   , 
      codestoque integer  (11)   , 
      codforn integer  (11)   , 
      doc varchar  (255)   , 
      datamov date   , 
      atualizaval varchar  (255)   , 
      vtotalgeral float  (10,2)   , 
      EstOrigem integer  (10)   , 
      EstDestino integer  (11)   , 
      codemp integer  (11)   , 
      obs blob sub_type 1   , 
      codapont integer  (11)   , 
      media varchar  (255)   , 
      codapmedia integer  (11)   , 
      QuemLevou varchar  (255)    NOT NULL , 
      placa varchar  (7)    NOT NULL , 
 PRIMARY KEY (codmov)); 

 CREATE TABLE tabmovestoqueitens( 
      id  integer generated by default as identity primary key     NOT NULL , 
      codmov integer  (11)   , 
      tipo varchar  (255)   , 
      tipomov varchar  (255)   , 
      codprod integer  (11)   , 
      qtdeprod float  (20,3)   , 
      vunitprod float  (10,2)   , 
      vtotalprod float  (10,2)   , 
      codemp varchar  (255)   , 
      codestoque integer  (11)   , 
 PRIMARY KEY (id)); 

 CREATE TABLE tabusuarios( 
      coduser  integer generated by default as identity primary key     NOT NULL , 
      usuario varchar  (255)    NOT NULL , 
      nomeuser varchar  (255)    NOT NULL , 
      cpf varchar  (11)   , 
      email varchar  (100)   , 
      frontpage_id integer  (11)   , 
      system_unit_id integer  (11)   , 
      active char  (1)   , 
      senha varchar  (255)   , 
      tipo varchar  (255)   , 
      codemp integer  (11)   , 
      situacao varchar  (255)   , 
      atualiza varchar  (255)   , 
      mensagem varchar  (255)   , 
      token_telegram varchar  (255)   , 
      chatid_telegram varchar  (255)   , 
      bot_telegram varchar  (255)   , 
 PRIMARY KEY (coduser)); 

 CREATE TABLE tabusuariosest( 
      coduser integer  (11)   , 
      id  integer generated by default as identity primary key     NOT NULL , 
      codest integer  (11)   , 
 PRIMARY KEY (id)); 

 CREATE TABLE tabusuariosfaz( 
      coduser integer  (11)   , 
      id  integer generated by default as identity primary key     NOT NULL , 
      codfaz integer  (11)   , 
 PRIMARY KEY (id)); 

 CREATE TABLE tabusuariosforn( 
      coduser integer  (11)   , 
      id  integer generated by default as identity primary key     NOT NULL , 
      codforn integer  (11)   , 
 PRIMARY KEY (id)); 

 CREATE TABLE tabusuariosmec( 
      coduser integer  (11)   , 
      id  integer generated by default as identity primary key     NOT NULL , 
      codmec integer  (11)   , 
 PRIMARY KEY (id)); 

 CREATE TABLE tabusuariospat( 
      coduser integer  (11)   , 
      id  integer generated by default as identity primary key     NOT NULL , 
      codpat integer  (11)   , 
 PRIMARY KEY (id)); 

 CREATE TABLE tbcadmaterial( 
      NUMPRD  integer generated by default as identity primary key     NOT NULL , 
      NOMPRD char  (40)    NOT NULL , 
      UNDPRD char  (3)    NOT NULL , 
      AUTORIZA char  (1)   , 
 PRIMARY KEY (NUMPRD)); 

  
 ALTER TABLE tabcadfornecedor ADD UNIQUE (nomefantasia);
 ALTER TABLE tabcadrequisicao ADD UNIQUE (n_requisicao);
 ALTER TABLE tabcadtrator ADD UNIQUE (codfrotatrat);
 ALTER TABLE tabcadtrator ADD UNIQUE (codpatrimonio);
  
 ALTER TABLE system_group_program ADD CONSTRAINT fk_system_group_program_2 FOREIGN KEY (system_group_id) references system_group(id); 
ALTER TABLE system_group_program ADD CONSTRAINT fk_system_group_program_1 FOREIGN KEY (system_program_id) references system_program(id); 
ALTER TABLE system_user_group ADD CONSTRAINT fk_system_user_group_2 FOREIGN KEY (system_user_id) references tabusuarios(coduser); 
ALTER TABLE system_user_group ADD CONSTRAINT fk_system_user_group_1 FOREIGN KEY (system_group_id) references system_group(id); 
ALTER TABLE system_user_program ADD CONSTRAINT fk_system_user_program_2 FOREIGN KEY (system_user_id) references tabusuarios(coduser); 
ALTER TABLE system_user_program ADD CONSTRAINT fk_system_user_program_1 FOREIGN KEY (system_program_id) references system_program(id); 
ALTER TABLE system_users ADD CONSTRAINT fk_system_user_2 FOREIGN KEY (frontpage_id) references system_program(id); 
ALTER TABLE system_users ADD CONSTRAINT fk_system_user_1 FOREIGN KEY (system_unit_id) references system_unit(id); 
ALTER TABLE system_user_unit ADD CONSTRAINT fk_system_user_unit_2 FOREIGN KEY (system_unit_id) references system_unit(id); 
ALTER TABLE system_user_unit ADD CONSTRAINT fk_system_user_unit_1 FOREIGN KEY (system_user_id) references system_users(id); 
ALTER TABLE tabcadcentrodecustos ADD CONSTRAINT fk_usuario FOREIGN KEY (coduser) references tabusuarios(coduser); 
ALTER TABLE tabcadfazenda ADD CONSTRAINT fk_cidade FOREIGN KEY (codcidade) references tabcadcidade(codcidade); 
ALTER TABLE tabcadmotorista ADD CONSTRAINT fk_transportadora FOREIGN KEY (NUMTRN) references tabcadtransportadora(NUMTRN); 
ALTER TABLE tabcadrequisicao ADD CONSTRAINT fk_estoque FOREIGN KEY (estoque) references tabestoque(codestoque); 
ALTER TABLE tabcadrequisicao ADD CONSTRAINT fk_usuario FOREIGN KEY (user_id) references tabusuarios(coduser); 
ALTER TABLE tabcadrequisicao ADD CONSTRAINT fk_patrimonio_tipo FOREIGN KEY (TIPPAT) references tabcadpatrimonio_tipo(CODTPAT); 
ALTER TABLE tabcadrequisicao ADD CONSTRAINT fk_fornecedor FOREIGN KEY (tabcadfornecedor_id) references tabcadfornecedor(codfornecedor); 
ALTER TABLE tabcadrequisicao ADD CONSTRAINT fk_patrimonio FOREIGN KEY (tabcadpatrimonio_id) references tabcadtrator(codtrator); 
ALTER TABLE tabcadrequisicao ADD CONSTRAINT fk_transportadora FOREIGN KEY (tabcadtransportadora_id) references tabcadtransportadora(NUMTRN); 
ALTER TABLE tabcadrequisicao ADD CONSTRAINT fk_mecanico FOREIGN KEY (tabcadmecanico_id) references tabcadmecanico(codmec); 
ALTER TABLE tabcadrequisicao ADD CONSTRAINT fk_fazenda FOREIGN KEY (tabcadfazenda_id) references tabcadfazenda(codfaz); 
ALTER TABLE tabcadrequisicao_itens ADD CONSTRAINT fk_requisicao FOREIGN KEY (tabcadrequisicao_id) references tabcadrequisicao(id); 
ALTER TABLE tabcadrequisicao_itens ADD CONSTRAINT fk_tabcadmateriais FOREIGN KEY (tabcadmaterial_id) references tabcadmaterial(codmaterial); 
ALTER TABLE tabcadrequisicao_servico ADD CONSTRAINT fk_tbcadrequisicao_servico_1 FOREIGN KEY (tabcadservico_id) references tabcadmaterial(codmaterial); 
ALTER TABLE tabcadrequisicao_servico ADD CONSTRAINT fk_tbcadrequisicao_servico_2 FOREIGN KEY (tabcadrequisicao_id) references tabcadrequisicao(id); 
ALTER TABLE tabcadtrator ADD CONSTRAINT fk_patrimonios_1 FOREIGN KEY (codtipopat) references tabcadpatrimonio_tipo(CODTPAT); 
ALTER TABLE tabestoquefaz ADD CONSTRAINT fk_estoque FOREIGN KEY (codestoque) references tabestoque(codestoque); 
ALTER TABLE tabestoquefaz ADD CONSTRAINT fk_fazenda FOREIGN KEY (codfaz) references tabcadfazenda(codfaz); 
ALTER TABLE tablantransporte ADD CONSTRAINT fk_aplicacao FOREIGN KEY (aplicacao) references tabcadaplicacao(id); 
ALTER TABLE tablantransporte ADD CONSTRAINT fk_Destinatario FOREIGN KEY (tablantransporteDestinatario) references tablantransporteDestinatario(id); 
ALTER TABLE tablantransporte ADD CONSTRAINT fk_emitente FOREIGN KEY (tablantransporteEmitente) references tablantransporteEmitente(id); 
ALTER TABLE tablantransporte ADD CONSTRAINT fk_MotoristaTerceiro FOREIGN KEY (Motorista_terceiro) references tabcadmotorista(id); 
ALTER TABLE tablantransporte ADD CONSTRAINT fk_transportadoraTerceira FOREIGN KEY (Transportadora_terceira) references tabcadtransportadora(NUMTRN); 
ALTER TABLE tablantransporteProduto ADD CONSTRAINT fk_tablantransporteProduto FOREIGN KEY (id_tablantransporte) references tablantransporte(id); 
ALTER TABLE tabmovestoque ADD CONSTRAINT fk_usuario FOREIGN KEY (codcc) references tabusuarios(coduser); 
ALTER TABLE tabmovestoque ADD CONSTRAINT fk_EstDestino FOREIGN KEY (EstDestino) references tabestoque(codestoque); 
ALTER TABLE tabmovestoque ADD CONSTRAINT fk_EstOrigem FOREIGN KEY (EstOrigem) references tabestoque(codestoque); 
ALTER TABLE tabmovestoqueitens ADD CONSTRAINT fk_produto FOREIGN KEY (codprod) references tabcadmaterial(codmaterial); 
ALTER TABLE tabmovestoqueitens ADD CONSTRAINT fk_tabmovestoque FOREIGN KEY (codmov) references tabmovestoque(codmov); 
ALTER TABLE tabusuariosest ADD CONSTRAINT fk_usuario FOREIGN KEY (coduser) references tabusuarios(coduser); 
ALTER TABLE tabusuariosest ADD CONSTRAINT fk_estoque FOREIGN KEY (codest) references tabestoque(codestoque); 
ALTER TABLE tabusuariosfaz ADD CONSTRAINT fk_usuario FOREIGN KEY (coduser) references tabusuarios(coduser); 
ALTER TABLE tabusuariosfaz ADD CONSTRAINT fk_fazenda FOREIGN KEY (codfaz) references tabcadfazenda(codfaz); 
ALTER TABLE tabusuariosforn ADD CONSTRAINT fk_usuario FOREIGN KEY (coduser) references tabusuarios(coduser); 
ALTER TABLE tabusuariosforn ADD CONSTRAINT fk_fornecedor FOREIGN KEY (codforn) references tabcadfornecedor(codfornecedor); 

  
