Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
816 views
in Technique[技术] by (71.8m points)

sql - Does a many-to-many relationship with a recursive one-to-many in mysql require at least 4 tables?

I have the following relationships (Business rules):

  • User_Company : Many-to-many (multiple companies per user, multiple users per company)
  • Ownership : One-to-One (For each entry in relationship table, it specifies whether user is an owner or employee. If owner then a percentage must be there)
  • Company_ownership : One-to-many for company (Recursive relationship), as another company can also be an owner in a company, percentage must be given.

So ownership or a company can be made up of a number of companies and users.

So I have developed the following:

one-to-many-recursive

So does there have to be at least 4 tables for this sort of relationship or can it be simplified. I feel it is quite complicated and would not be intuitive for another developer? How could it be optimized and elegantly arranged?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think ownership and employment are different concepts, that would be more advised to have them separated.
Think about John who is one of the owners of A company and in the mean time he is the CTO of A.

Company and People can have a base to reduce redundancy of entities.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...