Thread: Multiway associations

Multiway associations

From
Russell Shaw
Date:
Hi,
I'm making my first database.

I have a list of parts, each of which is sold by multiple
vendors. I also have a list of vendors, each of which sell
multiple parts.

How should i arrange the tables for this that doesn't involve
having lots of empty fields "just in case" ?


Re: Multiway associations

From
Paul Thomas
Date:
On 25/01/2004 05:06 Russell Shaw wrote:
> Hi,
> I'm making my first database.
>
> I have a list of parts, each of which is sold by multiple
> vendors. I also have a list of vendors, each of which sell
> multiple parts.
>
> How should i arrange the tables for this that doesn't involve
> having lots of empty fields "just in case" ?


One way would be to have a separate vendorpart table something like

CREATE TABLE vendorpart
(
   vendor_id      int4,
   part_id        int4
);

which holds the relationships. You'll to define indexes, contraints and
foreign keys on it.
--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants         |
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+