Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Edit -- I didn't think properly about it the first 3 times through... I vote for -- (Number 3 solution)</p> <p>Users</p> <pre><code>user id (pk) </code></pre> <p>Computers</p> <pre><code>computer id (pk) primary user id (fk -&gt; computer users id) </code></pre> <p>Computer Users</p> <pre><code>user id (pk) (fk -&gt; user id) computer id (pk) (fk -&gt; user id) </code></pre> <p>This is the best solution I can think of.</p> <p>Why I like this design.</p> <p>1) Since this is a relationship involving computers and users I like the idea of being able to associate a user to multiple computers as the primary user. This may not ever occur where this database is being used though.</p> <p>2) The reason I don't like having the primary_user on the link table </p> <pre><code> (computer_users.primary_user_id fk-&gt; users.user_id) </code></pre> <p>is to prevent a computer from ever having multiple primary users.</p> <p>Given those reasons Number 3 solution looks better since you will never run into some possible problems I see with the other approaches.</p> <p>Solution 1 problem - Possible to have multiple primary users per computer.</p> <p>Solution 2 problem - Computer links to a primary user when the computer and user aren't link to each other.</p> <pre><code>computer.primaryUser = user.user_id computer_users.user_id != user.user_id </code></pre> <p>Solution 3 problem - It does seem kind of odd doesn't it? Other than that I can't think of anything.</p> <p>Solution 4 problem - I can't think of any other way of doing it.</p> <hr> <p>This is the 4th edit so I hope it makes sense still.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload