Having an optional foreign key (ie. sometimes NULL) ?

Поиск
Список
Период
Сортировка
Hello,

  I have the following tables:

    - company (eg. ABC Shipping Inc.)
    - product (eg. table, chair, pen, pencil)
    - client (eg. Joe's Insurance Company)

and they relate to each other as follows:

    - a company has clients (company is a foreign key in client)
    - a company sells products (company is a foreign key in client)

which is all well and good until I come to one specification in my design
document which says that "some products will only be available to a single
client whereas other products will be available to all clients".

  I thought the best way to get around this would be to have the client as a
foreign key in products but for products available to all clients this won't
work.

  Can someone advise how I can overcome this?

  Thanks, Tom.

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