Thread: Foreign key
What's the best way to build a relation between two tables ?
I know that Foreign key is no longer supported.
Uh...I think foreign keys are supported:
CREATE TABLE main
( id INTEGER,
data TEXT );
CREATE TABLE secondary
( mainid INTEGER REFERENCES main(id),
data TEXT );
That will make your joins:
SELECT * FROM main,secondary WHERE id = mainid;
much more efficient.
-Robby
-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]On Behalf Of Lorenzo De Vito
Sent: Thursday, August 02, 2001 11:24 AM
To: pgsql-sql@postgresql.org
Subject: [SQL] Foreign keyWhat's the best way to build a relation between two tables ?I know that Foreign key is no longer supported.
Where did you get the idea that Foreign Key was no longer supported? It works fine on my 7.1.2 box: processdata=> select version(); version ---------------------------------------------------------------PostgreSQL 7.1.2 on i686-pc-linux-gnu, compiled by GCC 2.95.4 (1 row) processdata=> CREATE TABLE foo (tes_key varchar(5) PRIMARY KEY); NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'foo_pkey' for table 'foo' CREATE processdata=> CREATE TABLE bar (bar_key SERIAL, foo_id varchar(5) REFERENCES foo); NOTICE: CREATE TABLE will create implicit sequence 'bar_bar_key_seq' for SERIAL column 'bar.bar_key' NOTICE: CREATE TABLE/UNIQUE will create implicit index 'bar_bar_key_key' for table 'bar' NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s) CREATE Good Luck, Jason --- Lorenzo De Vito <lorenzodevito@email.it> wrote: > What's the best way to build a relation between two > tables ? > I know that Foreign key is no longer supported. > __________________________________________________ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/
Lorenzo De Vito wrote: > What's the best way to build a relation between two tables ? > I know that Foreign key is no longer supported. Who told you so? Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com # _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com