## What is an ER diagram?

An Entity Relationship (ER) Diagram is a type of flowchart that illustrates how “entities” such as people, objects or concepts relate to each other within a system. ER Diagrams are most often used to design or debug relational databases in the fields of software engineering, business information systems, education and research. Also known as ERDs or ER Models, they use a defined set of symbols such as rectangles, diamonds, ovals and connecting lines to depict the interconnectedness of entities, relationships and their attributes. They mirror grammatical structure, with entities as nouns and relationships as verbs.

ER diagrams are related to data structure diagrams (DSDs), which focus on the relationships of elements within entities instead of relationships between entities themselves. ER diagrams also are often used in conjunction with data flow diagrams (DFDs), which map out the flow of information for processes or systems.

## What Is an Entity in ERDs?

Before we look at some examples, let's talk about some of the key terms/components that'll make up the entity relationship diagrams we'll be working with.

The first is the **entity**. An entity simply represents an object in our database. This could be an object for users, courses, products, and so on.

Note that the name of every entity should be singular (user) and not plural (users).

Here is what an entity looks like:

The diagram above shows an entity called user. This entity will have information about the various users registered on a platform.

In the next section, we'll talk about attributes.

## What Are Attributes in ERDs?

We've talked about entities and we know they store some sort of information about the object they're representing.

The information about an object is the attributes. So we can say the properties of an entity are the attributes.

Let's represent this using a diagram.

The entity in the diagram above has three attributes – username, age, and email.

Now you have a clearer picture of what an entity is and its attributes.

If you still find this confusing, the entity above is called "User". The entity has three properties (username, age, and email) which are referred to as the entity's attributes.

## Relationship Between Entities in ERDs

In the previous sections, we talked about entities and their attributes. In most cases, databases are made up of more than one entity.

To understand the relationship between one entity and another, we use lines to connect them. But these lines have notations (indicators) on them to specify the type of relationship that exists between two entities.

We'll use crow's foot notation to specify our entity relationships.

### Symbols in Crow’s Foot Notation and Their Meaning

Before we see diagrams of the symbols associated with crow's foot notation, we need to discuss a key term in crow's foot notation.

One of the most important terms to know when using crow's foot notation is **cardinality**.

**Cardinality **acts as a parameter for the relationship between entities. For one entity, there is a minimum and maximum number that helps define its relationship with another entity.

Don't worry if these explanations seem confusing. As we go further, you'll understand them perfectly.

Here are the symbols associated with the crow's foot notation:

#### Zero

The symbol/diagram above denotes zero in crow's foot notation. We know this because the of the zero/circle indicator at the right side of the horizontal line.

#### One

The diagram above shows a horizontal line with a short vertical lines crossing it. The vertical line acts as the indicator – it denotes one.

#### Many

The diagram above denotes many. You can easily remember this symbol because it looks like a crow's foot.

The three diagrams above are the basic representation of indicators in crow's foot notation. But in most cases, these indicators are combined to fully understand the relationship between entities.

By the time we start looking at some practical examples, you'd understand the meaning of these symbols better.

Before that, let's take a look at more diagrams and what they mean. We won't be introducing anything new – just a combination of the diagrams above.

#### Zero or Many

As can be seen above, the **zero or many **symbol/indicator in crow's foot notation is a combination of the zero and many indicators.

#### One or Many

As expected, the **one or many **indicator is a combination of two indicators – one and many.

#### One and only one

The **one and only one **indicator has two "one" indicators. In our examples in the next section, you'll understand its use better.

## How to Use Crow’s Foot Notation in Entity Relationship Diagrams

In the last section, we focused on crow's foot notation diagrams and what they mean. They serve as indicators that explain the relationship between one entity and another.

In this section, we'll dive in and look at some practical examples – this will help you fully understand how to use the crow's foot notation.

If you have been following along from the previous sections, then some aspects of the diagrams we'll use in this section should be clear to you.

### Crow's Foot Notation Example #1

In this example, we'll start with an assumption, create entities and denote their relationship using crow's foot notation.

We'll break this example into steps with diagrams leading to the final sketch.

##### Step #1 - Our Assumption and Entities

Let's assume we have two entities in our database. A teacher and course entity. Here's a representation of that:

##### Step #2 - Relationship of the Teacher Entity and the Course Entity

Since we're the ones creating this model of the database, we get to set the rules! So for every teacher, they can only teach one course.

We'll assume this is a platform where users are taught programming languages. Each teacher can only teach one programming language.

The notation here will be **one and only one**. The notation will be placed on the right side of the horizontal line.

Here's an entity relationship diagram for that:

Remember when we talked about **cardinality**? Well, this is the perfect place to see it in practice. The minimum number of courses a teacher can take up is one, and the maximum is also one.

##### Step #3 - Relationship of the Course Entity and the Teacher Entity

For each course, we want to have one or many teachers to choose from – meaning that one course can be taught by one or many teachers. The minimum here will be one while the maximum will be many.

So the user can have one or many JavaScript teachers to learn from, one or many Python teachers to learn from, and so on.

The notation to be used is **one or many**. The notation will be placed on the left side of the horizontal line.

Here is the ERD:

### Crow's Foot Notation Example #2

The notations don't always have to be different. What matters is the logic behind the relationship between entities. This is entirely up to the those creating or designing the database.

Have a look at the diagram below.

We have two entities – Customer and Pizza. These entities are linked together by a horizontal line with symbols/indicators/notations.

Let's begin with the notation on the left. It has the **zero or many **notation. This implies that a pizza can be ordered by none (optional) or many customers.

Similarly, the notation on the right side implies that a customer can order **zero or many **pizzas.

The **cardinality **here is the same for both entities. Zero is the minimum while many is the maximum.

The use cases for other crow's foot notation diagrams are the same as the ones in our examples. It all depends on the logic and what you're designing.