Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want the constraint to be that one person has at most one primary address, a <code>Persons.PrimaryAddressID</code> is clearly simpler -- indeed, it's enforced by the very schema. It's also easy to ensure <em>exactly one</em> primary address per person (just make that column be not null), and if you need to, even say that no two people can share a primary address (just make that column be unique).</p> <p>Of course, exactly because this approach excels at enforcing such simple constraints, it's bad when you <em>don't</em> want these constraints -- for example, if you want to make it possible for a person to have more than one "primary" address, the approach in question would not work.</p> <p>Incidentally, I would not consider a one-Person/many-addresses relationship to be particularly good <em>unless</em> you want to enforce the fact that no two people can share the same address: in general, in a normalizing mood, I'd rather have a table of people, one of addresses, and one for the relationship (which in most contexts would naturally be many-to-many, since many people can, and in real life do, share the same address).</p> <p>If you choose to go this route, then, especially if you need high flexibility (multiple primary addresses &amp;c), having the relationship table carry the "primality" boolean would be an attractive choice (it still makes it not too hard to enforce some of the above-mentioned constraints, though other constraints, such as "an address belongs to at least one person" or vice versa, can be tricky to express simply).</p> <p>Lesson to retain: express exactly what constraints your schema needs to express simply, and the right schema for that purpose often emerges quite clearly. If the constraints of interest are a mystery, so will be the answer to the question "what's the right schema";-).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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