Re: Question about Foreign key! - Mailing list pgsql-general

From Patrick Welche
Subject Re: Question about Foreign key!
Date
Msg-id 20010727165152.A19967@quartz.newn.cam.ac.uk
Whole thread Raw
In response to Question about Foreign key!  (Fariba Noorbakhsh <fNoorbakhsh@tecways.com>)
List pgsql-general
On Fri, Jul 27, 2001 at 04:33:24PM +0200, Fariba Noorbakhsh wrote:
> Hi everybody,
>
> Is there anyway to define foreign Key ,.. (constraints) after creating
> table?
> As far I know, you can't do it with ALTER table!!!

template1=# \h alter table
Command:     ALTER TABLE
...
ALTER TABLE table
    ADD table constraint definition
...


eg:
                        Table "tblPerson"
         Attribute         |           Type           | Modifier
---------------------------+--------------------------+----------
 ID                        | integer                  |
...
                Table "tblAddress"
 Attribute  |           Type           | Modifier
------------+--------------------------+----------
 ID         | integer                  |
 PersonID   | integer                  |
...

create unique index tblperson_pkey on "tblPerson"("ID");
alter table "tblAddress"
  add constraint addfk
  foreign key("PersonID") references "tblPerson"("ID") match full;


Hope this helps,

Patrick

pgsql-general by date:

Previous
From: missive@frontiernet.net (Lee Harr)
Date:
Subject: Re: Better backtrace (wasRe: pqReadData() -- backend closed the channel unexpectedly.)
Next
From: "Ryan C. Bonham"
Date:
Subject: Visual Basic and PostgreSQL ODBC