Entity Relationship Diagrams

Entity relationship diagrams(ERD) are a graphical representation that help us understand a particular system. As a result, ERDs are featured frequently in database design.

Let’s cover the basics of an ERD.

Entity

The first part is the entity. Entities simply represent an object in our database and can be visualised as shown below:

Entity

This diagram is an entity in our ERDs, and is called ‘order’. This entity will have information about the orders that are placed within an establishment. Contained within entities are what are known as attributes.

Attributes

So now that we know that entities contain information about some object. Attributes are the information within that entity describing the object.

Continuing on the above example, attributes are represented as follows:

Entity and attribute

Here we can see that the entity is called ‘order’, and the attributes within are ‘order_id’, ‘order_name’ and ‘category’.

Creating Relationships Between ERDs

Databases will often contain multiple ERDs and many relationships may exist between them. Lines are utilised in order to represent these relationships, and they are made using crows foot notation.

Now when understanding crows foot notation, one important concept to know is cardinality. Cardinality states that there is a minimum and maximum number that defines a relationship between two entities.

Here are the symbols utilised in crows foot notation to describe these relationships.

Zero

Zero

The diagram above represents a zero in crows feet notation. It can be used when one entity may have no relationship to another.

One

One

This diagram represents a one in crows feet notation, and can be used when an entity may have one relationship to another.

Many

Many

Many is represented in crows feet notation by the diagram above. It can be used when one entity has multiple relationships to another.

Combining these Notations

Zero to One

Often, these notations are combined to represent the relationship between two entities. First off, the zero to one notation is illustrated below:

Zero to one

This states that an entity may have zero to one relationship to another. For example, for fictional entities person and marriage, we can put a zero to one notation from person to marriage, as they are either not married(0) or they are (1).

Zero to one

Zero to Many

Moving on, the zero to many notation is illustrated below. Zero to many notations mean that one entity, can have zero to many relationships to another.

Zero to many

For example, in fictional entities ‘consumer’ and ‘burger’, a consumer can purchase 0 burgers, or they can purchase any number above zero also.

Zero to many

One to Many

For the last notation, we have the one to many relationship, and as you may have guessed, this represents that one entity may have one or more relationships to another.

One to many

For example, between ‘person’ and ’given name’ entities, one person can have one given name, or they may have multiple as shown below.

One to many

Now that you understand the basics of ERDs, you’ll be able to understand how a database is designed should you come across it. You can also start designing ERDs of your own here!