ERDs
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.
Note that the name of every entity should be singular (user) and not
plural (users).
The diagram above shows an entity called user. This entity will have
information about the various users registered on a platform.
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.
One of the most important terms to know when using crow's foot notation
is cardinality.
Here are the symbols associated with the crow's foot notation:
Zero
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.
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
One or Many
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.
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.
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.