Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Consider two tables for People and their addresses: </p> <pre><code>People (pid, prefix, firstName, lastName, suffix, DOB, ... primaryAddressTag ) AddressBook (pid, tag, address1, address2, city, stateProv, postalCode, ... ) </code></pre> <p>The Primary Key (that uniquely identifies each and every row) of People is <code>pid</code>. The PK of AddressBook is the composition of pid and tag <code>(pid, tag)</code>.</p> <p>Some example data:</p> <h2>People</h2> <pre><code>1, Kirk 2, Spock </code></pre> <h2>AddressBook</h2> <pre><code>1, home, '123 Main Street', Iowa 1, work, 'USS Enterprise NCC-1701' 2, other, 'Mt. Selaya, Vulcan' </code></pre> <p>In this example, Kirk has two addresses: one 'home' and one 'work'. One of those two can (and should) be noted as a foreign key (like a cross-reference) in <code>People</code> in the primaryAddressTag column.</p> <p>Spock has a single address with the tag 'other'. Since that is Spock's only address, the value 'other' ought to go in the <code>primaryAddressTag</code> column for pid=2.</p> <p>This schema has the nice effect of preventing the same person from duplicating any of their own addresses by accidentally reusing tags while at the same time allowing all other people use any address tags they like.</p> <p>Further, with FK references in <code>primaryAddressTag</code>, the database system itself will enforce the validity of the primary address tag (via something we database geeks call referential integrity) so that your -- or any -- application need not worry about it.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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