Edit - I did not think about it at first three times ... I vote for - (Decision number 3)
Users
user id (pk)
Computers
computer id (pk) primary user id (fk -> computer users id)
Computer users
user id (pk) (fk -> user id) computer id (pk) (fk -> user id)
This is the best solution I can think of.
Why I like this design.
1) Since this is a relationship related to computers and users, I like the idea of associating a user with multiple computers as the primary user. This may not happen when this database is used.
2) The reason I don't like having primary_user in the link table
(computer_users.primary_user_id fk-> users.user_id)
means that the computer does not have several primary users.
Given these reasons, solution # 3 looks better, since you will never encounter some of the possible problems that I see with other approaches.
Problem Solution 1 - It is possible to have several primary users on the computer.
Problem 2 - the computer connects to the main user when the computer and the user are not connected to each other.
computer.primaryUser = user.user_id computer_users.user_id != user.user_id
Problem of the 3rd solution. That seems weird, doesn't it? Other than that, I can't think of anything.
Problem Solution 4 - I can't think of another way to do this.
This is the fourth edit, so I hope this makes sense.
Simurr
source share