Doubt how to make Insert in this model

Asked

Viewed 150 times

5

I am developing an application that has the need to have a natural person and a legal, I would like help to know how would be the insert of this model inserir a descrição da imagem aqui

If I want to register a natural person I must do two insert?

1 answer

2

Yes. First you enter the parent table (tbPessoa) and then the daughter table (tbPessoaFisica or tbPessoaJuridica).

INSERT INTO tbPessoa ('nmPessoa', 'dsEmail')
VALUES ('João', '[email protected]');

INSERT INTO tbPessoaFisica ('cdCpf', 'idPessoa')
VALUES ('78945698745', 'pk do insert de cima');
  • In the case of the method that will do the Insert will have two sql string =

  • and will have two pst.execute();? or one only?

  • Since you use JDBC, you’ll get two Sqls. Take a look at this link: https://javahunter.wordpress.com/2011/03/23/use-of-prepared-statement-and-getting-foriegn-key-from-master-table/

  • All right, thank you

  • Insert worked fine, but now I can use this logic to update my client right?

  • Exact. Use the same logic. :)

  • All right, thank you so much for your help.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.