Problem with n to n relation

Поиск
Список
Период
Сортировка
От Janning Vygen
Тема Problem with n to n relation
Дата
Msg-id 0110051239400B.30993@janning
обсуждение исходный текст
Ответы Re: Problem with n to n relation  (Morgan Curley <mcurley@e4media.com>)
Список pgsql-sql
Hi,

i create n to n relations like this, right?

create table person ( id    serial, name  text
);

create table address ( id     serial, street text ...
);

create table person2adress ( id         serial, person_id  integer not null references person(id), address_id integer
notnull references address(id),
 
);

than i can select all adresses from one person with id =1 with
select street 
from address 
where id =  (    select adress_id     from person2adress     where person_id = 1 );

ok so far so good. but you can still insert persons without any 
adress. so its a 0..n relation. But how van i achieve that you can´t 
insert any person without adress???

thanks in advance
janning


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

Предыдущее
От: Haller Christoph
Дата:
Сообщение: Re: challenging query
Следующее
От: Morgan Curley
Дата:
Сообщение: Re: Problem with n to n relation