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