En/ty
Represents
a component, object or a concept of a system. Concepts described by an
entity can be concrete, such as a student or a car, or abstract, such as an event or a
schedule. Entities are translated as tables when creating your database schema. They
are commonly illustrated as rectangles in most ER diagrams:
The Student entity
Entities in Crow's Foot notation also include a list of attributes
or properties that
define them. For a user entity, its attributes could be username, password and email.
The User entity
Rela/onship
A relationship tells you how two entities interact with each other and it's usually
represented as a verb surrounded by a diamond. For example, think about a student
entity and a class entity. Their relationship could be described as follows:
Relation between entities
Saving Data on Android
Chapter 7: Mastering Relations
raywenderlich.com
122
In this ER diagram, the relationship is described as "takes" and you could read it left
to right:
A student takes a class
.
Or right to left:
A class is taken by a student.
Note:
Not all ER diagrams illustrate the relationship between their entities
since it is often easy to infer from the context. In Crow's Foot notation, it is
usually omitted.
Cardinality
Last but not least, the cardinality tells you the kind of relationship two entities have.
There are three main cardinal relationships:
One to one:
When one entity can only be related to one and
only one instance of the
other entity. For example, a department on a company can only have one head of
department, and that head of department can only lead one department:
One to One relation
Saving Data on Android
Chapter 7: Mastering Relations
raywenderlich.com
123
One to many:
When one entity can be related to many instances of another entity.
For example, a teacher can teach many classes in a single semester, but a class can
only have one teacher:
One to Many relation
Many to many:
When many instances of an entity can also be related to many
instances of another entity. For example, a book (like this one) can have many
authors, and authors can write many books:
Many to Many relation
Cardinalities can also have constraints that indicate the minimum and maximum
numbers in the relationships:
One and only one
,
zero or one
,
zero or many
and
one or
many
.
Here is the full list of cardinalities and constraints that you can find:
ER Cardinalities
Saving Data on Android
Chapter 7: Mastering Relations
raywenderlich.com
124
Now that you know how ER diagrams work, you will now learn how to create
relationships using
Do'stlaringiz bilan baham: