Re: foreign vs primary key

From: --CELKO-- <71062.1056_at_compuserve.com>
Date: 20 Sep 2001 04:38:19 -0700
Message-ID: <c0d87ec0.0109200338.2144dabe_at_posting.google.com>


>> I have read a number of texts regarding the terms foreign and
primary keys
but I just can't get a feel for their uses. <<

A key is one or more columns which uniquely identify a row in a table.  The primary key is the one key we picked out to be special. This originally came from Dr. Codd's papers, but he later said that a key is a key. SQL picked up the idea, however, and most SQL implementations do somethihg special to speed up access via the PRIMARY KEY. In SQL, you also have the UNIQUE() constraint that can be used to create keys.

a FOREIGN KEY might or might not be key in the talbe in which it appears, but it is a key in a second table. The two tables involved are called the referencing table and the referenced table.

NEVER use the terms "parent" and "child" -- it is completely wrong. Those terms are from heirarchical and network databases. The referencing table and the referenced table can be the same in SQL.

A FOREIGN KEY defaults to the PRIMARY KEY in the referenced table, but it can also reference any other key created with UNIQUE constriants. Keys can overlap, too.

Look up referential actions in a book. This is how you maintain relationships among tables in a schema. Received on Thu Sep 20 2001 - 13:38:19 CEST

Original text of this message