Re: Tutorial : using foreign keys, retrictions etc

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: Tutorial : using foreign keys, retrictions etc
Дата
Msg-id Pine.BSF.4.21.0106060838490.15539-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на Tutorial : using foreign keys, retrictions etc  (Mario Bittencourt <mneto@argo.com.br>)
Список pgsql-sql
On Sat, 2 Jun 2001, Mario Bittencourt wrote:

> Hi,
> 
>         I've decided to switch from mysql to postgresql as my database server. I 
> do mostly web programming (who doesnt these days?) with more than a 100 
> sites developed (using mysql).
> 
>         I've read about postgresql and it's features (such as triggers, stored 
> procedures, views) and I'd like to know if there is some tutorial/snippet 
> of code regarding such features specially  the use of foreign keys and 
> referetial integrity.
> 
>         To give a more concrete example the next app I'd like to use postgresql 
> needs this behaviour :
> 
> table A
> id,  name
> 
> table B
> id, foo
> 
> table C
> id, date
> 
>         If I change id in table A update table B to change it too (I think it's 
> called cascade).

In this case it's pretty easy, 
table B needs a foreign key defined like:FOREIGN KEY (id) REFERENCES A(id) ON UPDATE CASCADE
(you may want ON DELETE CASCADE as well, it depends).

I believe someone had written a document on FK, but I'm not entirely sure
what happened to it or whether it ended up in the docs.  For examples
without much explanation you can look at the foreign key regression test,
but that's not alot of help.




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

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: help with a function
Следующее
От: Stephan Szabo
Дата:
Сообщение: Re: audit trail and system catalogs