Re: Adding a Foreign Key

From: "Joe Conway" <joseph(dot)conway(at)home(dot)com>
To: <tankgirl(at)worldonline(dot)es>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Adding a Foreign Key
Date: 2001-09-03 17:21:51
Message-ID: 018e01c1349c$ebbf9b70$0705a8c0@jecw2k1
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Hello everyone,
>
> I know that a Primary Key can be added to a table before it has been
created, doing this...
>
> CREATE UNIQUE INDEX table_pkey ON table (atribute);
>
> Well I wonder if a Foreign Key can also be added and what syntax does it
follow.
>
> Thankyou in advance.
>
> Stay Safe & Happy.
>
> :* TankGirl

See:

http://www.postgresql.org/idocs/index.php?sql-altertable.html

The part you're interested in says:

To add a foreign key constraint to a table:
ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address)
REFERENCES addresses(address) MATCH FULL

Hope this helps,

-- Joe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2001-09-03 17:23:38 Re: query not using index
Previous Message Andrew Snow 2001-09-03 17:06:32 Re: Perl won't eval PgSQL boolean value