FOREIGN KEY ... REFERENCES ...

From: Nabil Sayegh <nsmail(at)sayegh(dot)de>
To: pgsql-novice(at)postgresql(dot)org
Subject: FOREIGN KEY ... REFERENCES ...
Date: 2001-01-18 14:28:02
Message-ID: 3A66FD72.2204BCAE@sayegh.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

Browse pgsql-novice by date

  From Date Subject
Next Message zivit 2001-01-18 16:28:14 ERROR: plpgsql: cache lookup from pg_proc failed -- Why?
Previous Message Robert D. Nelson 2001-01-18 13:12:00 RE: Postgres superuser & password on Red Hat; upgrade