Re: Question about Foreign key!

Поиск
Список
Период
Сортировка
От Patrick Welche
Тема Re: Question about Foreign key!
Дата
Msg-id 20010727165152.A19967@quartz.newn.cam.ac.uk
обсуждение исходный текст
Ответ на Question about Foreign key!  (Fariba Noorbakhsh <fNoorbakhsh@tecways.com>)
Список 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 по дате отправления: