5. Entity Relationship Diagrams (3)

There are only a limited number of relationships possible with ER diagrams. Relationships are drawn as lines between entities.

One to One

In this case there is only one entity either side of the relationship. It is shown as a single line between entities

For example, in the diagram below for each product there is only one supplier and conversely for each supplier there is only one product.

One to One Entity relationship

One to Many

In this case one entity may be related to many instances of another entity. It is shown as a line with a small three pronged branch at one end.

For example, in the diagram below it is stating that each product has many (more than one) different suppliers. Note that a foreign key can only be set on the 'many' side of a relationship.

Entity one to many relationship

You can also show the reverse as a Many-to-One relationship. In the example below a single supplier is related to many products

ER Many to one relationship

Many to Many

In this case each entity is related to many instances of another entity. A many to many relationship is shown below

ER many to many relationship

You cannot implement this directly in a database. Instead you need to create a third, 'link' entity that helps relate the main two entities together. The new entity needs to include a foreign key from each entity. Note again that the foreign key is on the 'many' side of the diagram. This can be seen below

ER Link entity

 

challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: Drawing ER diagrams