Re: Making a foreign key chain - good idea or bad idea?

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: Making a foreign key chain - good idea or bad idea?
Дата
Msg-id Pine.BSF.4.21.0101241225520.58399-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на Making a foreign key chain - good idea or bad idea?  (Frank Joerdens <frank@joerdens.de>)
Список pgsql-sql
On Wed, 24 Jan 2001, Frank Joerdens wrote:

> I just did something which seems to work alright and which makes sense
> to me now but which I have a funny feeling about. It may be good
> standard practice (and I just don't know about it) or dangerously
> foolish or just plain silly: I created a foreign key reference on a
> column that is also the primary key for this table as in
> 
> create table institute (
> id    int4 references index ( id ) PRIMARY KEY,
>  . . .
> 
> and then used that column as a reference for a foreign key constraint in
> a couple of other tables:
> 
> create table boss (
> institute_id   int4 references institute ( id ),
>  . . . 
> 
> create table staff (
> institute_id    int4 references institute ( id ),
>  . . . 
> 
> I am not really sure what happens when I delete or modify the id column
> in the table at the top of this "chain". Except for this uncertainty I
> don't think this scheme would pose a problem, but I may be wrong. Can
> anyone enlighten me?

If you mean index(id), as long as there exists an institute(id) that
references it, you won't be allowed to delete or update it to a distinct
value.  And, you won't be able to delete or update institute(id) as long
as there exists at least one boss(id) or staff(id) that references it.
You know that there shouldn't be orphaned boss(id) or staff(id) rows 
because those can't exist without a institute(id) row of the correct 
value and that requires the index(id) value.




В списке pgsql-sql по дате отправления:

Предыдущее
От: "Glen and Rosanne Eustace"
Дата:
Сообщение: Problem with Dates
Следующее
От: Najm Hashmi
Дата:
Сообщение: Re: How to change the ownership of the table?