Foreign keys?

Поиск
Список
Период
Сортировка
От Dr. Evil
Тема Foreign keys?
Дата
Msg-id 20010713003500.12027.qmail@sidereal.kz
обсуждение исходный текст
Ответы Re: Foreign keys?  (Jason Earl <jdearl@yahoo.com>)
Re: Foreign keys?  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Список pgsql-general
There doesn't seem to be much documentation on foreign keys and how to
use them properly.

I am setting up a DB with two tables: users, and a table of objects
where are always owned by users.  I want to make sure that there's no
way to have an object which isn't owned.  Let's say these are the
tables:

CREATE TABLE user (
       number INT4,
       name VARCHAR(400)
);

and

CREATE TABLE object (
       owner INT4,
       description VARCHAR(200)
);

The constraint is that there should never be a row in the object table
where the owner column has a number which doesn't have a corresponding
owner in the user table.

I'm sure I can do something with foreign keys to implement this
constraint, but I can't figure it out.

Thanks

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

Предыдущее
От: Adam Manock
Дата:
Сообщение: Re: Performance tuning for linux, 1GB RAM, dual CPU?
Следующее
От: Jason Earl
Дата:
Сообщение: Re: Foreign keys?