0

I'm creating a db schema that involves users that can have multiple users.

I want to register different companies to use the web services.

For example:

  • user A or B (etc) can signup and create a company account
  • user A can create multiple accounts of other users with their types, similarly user B

If user A or B create different accounts, how would I know this particular user is belong to User A or B company ? I think user table have many to many relationship with itself (like basic friendship design).

Please suggest the best design .

Ex.

User 3,4 belongs to User A

User 5,6 belongs to User B

1
  • 1
    Yes you are right you have manage many to many relationship with itself.. Commented Aug 28, 2016 at 11:36

1 Answer 1

3

In general, I would recommend starting by identifying all the entities you are trying to persist. It sounds like you have two distinct entities in your question. One being "user," which represents a single person. Your second entity is "company." A "user" can belong to a company.

An example of a database design would be one table for users, and one table for companies. In the "users" table, you would want to have a foreign key column that references the primary key (unique id) of the company the user belongs to. If each user can only belong to one company, this becomes a simple one to many relationship.

In short, I would highly recommend treating company accounts separately from user accounts, since they are fundamentally different entities.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.