FOREIGN KEY ... REFERENCES ... - Mailing list pgsql-novice

From Nabil Sayegh
Subject FOREIGN KEY ... REFERENCES ...
Date
Msg-id 3A66FD72.2204BCAE@sayegh.de
Whole thread Raw
List pgsql-novice
Hi,

after building some databases the naive way :( I consider now
to do it the right way.

In the past I created tables with "PRIMARY KEY" and "UNIQUE" being
the only constraints (well apart from NOT NULL and such).

Relations between Tables, Columns only existed when I joined them.

Now my question:
Apparently there are two ways of defining relations:
FOREIGN KEY and REFERENCES

======================================================================
REFERENCES Constraint

[ CONSTRAINT name ] REFERENCES reftable [ ( refcolumn ) ]

The REFERENCES constraint specifies a rule that a column value is
checked
against the values of another column. REFERENCES can also be specified
as
part of a FOREIGN KEY table constraint.
======================================================================
TABLE Constraints
[ CONSTRAINT name ] FOREIGN KEY ( column [, ... ] )
                    REFERENCES reftable [ ( refcolumn [, ... ] ) ]
======================================================================

Now I'm totally confused. Why should someone define a FOREIGN KEY
and not defining what it REFERENCES ? And vice versa ?

Could someone point me to a simple example 2 or 3 tables (bundles or the
like)
Perhaps with INDICES for fast querying ?

TIA

--
 Nabil Sayegh
 GPG-Key available at http://www.sayegh.de
 (see http://www.gnupg.org for details)

pgsql-novice by date:

Previous
From: "Stephen Hardman"
Date:
Subject: help
Next
From: "Stefan Waidele jun."
Date:
Subject: Interval output format