Database Modeling - Self Relationship

Asked

Viewed 636 times

0

My Case

I have a table empresa, this table has fields known as cnpj, razão social and login. This same company may register another in its catalogue of companies. The company registered by it will only be visible to it, and not to others.

What I thought

I’m dealing with a case of self relationship, correct. I would put a field on the table empresa pointing to the cnpj of the registered company. There when I need to display, just filter through the companies registered by the company x. It has as I put the cnpj and cnpj_estrangeiro as composite primary key ?

  • Perfectly possible. See this answer. http://answall.com/a/8433/36350

  • Since I am a little weak in SQL, I would create another table and relate COMPANY 1 to COMPANY 2. I would not create anything in the COMPANY table.

  • If you put cnpj and cnpj_estrangeiro as the primary key, how will you register the first company in the bank?

  • Answer explained in the link below: http://answall.com/questions/8408/howto functionRe%C3%A7%C3%A3o-between-the-same-table/8433#8433

No answers

Browser other questions tagged

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