Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The relational model says there's no essential difference between one key and another. That is, when a relation has more than one candidate key, there are no theoretical reasons for declaring that <em>this</em> key is more important than <em>that</em> key. Essentially, that means there's no theoretical reason for identifying one key as a <em>primary key</em>, and all the others as secondary keys. (There might be practical reasons, though.)</p> <p>Many relations have more than one candidate key. For example, a relation of US states might have data like this.</p> <pre><code>State Abbr Postal Code -- Alabama Ala. AL Alaska Alaska AK Arizona Ariz. AZ ... Wyoming Wyo. WY </code></pre> <p>It's clear that values in each of those three columns are unique--there are three candidate keys. </p> <p>If you were going to build a table in SQL to store those values, you might do it like this.</p> <pre><code>CREATE TABLE states ( state varchar(15) primary key, abbr varchar(10) not null unique, postal_code char(2) not null unique ); </code></pre> <p>And you'd do something like that because SQL doesn't have any other way to say "My table has three separate candidate keys."</p> <p>I didn't have any particular reason for choosing "state" as the primary key. I could have just as easily chosen "abbr" or "postal_code". Any of those three columns can be used as the target for a foreign key reference, too.</p> <p>And as far as that goes, I could have built the table like this, too.</p> <pre><code>CREATE TABLE states ( state varchar(15) not null unique, abbr varchar(10) not null unique, postal_code char(2) not null unique ); </code></pre>
    singulars
    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.
 

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