1

Team can have N users and users can have N teams.
One user can have N answers.
Answer belongs to one user.

UML

I need help to build database structure. Important is to get team record from any answer. User can answer only with one team

2
  • Add a TeamUser table containing the foreign keys UserID and TeamID. Use it to create the many to many relationship described in the first sentence of your question body. Mar 13, 2017 at 23:48
  • "User can answer only with one team." Sounds like you need to add an arrow between Answer and Team. Otherwise a solution is not possible.
    – John Wu
    Mar 14, 2017 at 0:24

1 Answer 1

3

Team can have N users and users can have N teams

As Robert Harvey commented, a Membership* table with userId and teamId (foreign keys) will enable the Many to Many relationship.

Answer belongs to one user.

The Answer table needs to have a userId (foreign key).

Important is to get team record from any answer. User can answer only with one team

The Answer table also needs teamId (foreign key).


*Thanks for the suggestion, JeffO, UserTeams was a stupid name :)

1
  • Or you could call the table Membership.
    – JeffO
    Mar 14, 2017 at 2:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.