ER Diagram
ER Diagram
Silmy
OUTLINE
• What is ER Diagram?
• Cardinality.
• Participation.
• Exercises.
WHAT IS ER DIAGRAM?
• ER Diagram stands for Entity Relationship Diagram, also
known as ERD.
• Cardinality.
• Participation.
• Exercises.
WHY USE ER DIAGRAM?
• It helps to describe entities, attributes, relationships.
• It provide a preview of how all your tables should connect, what fields are
going to be on each table.
• ER diagrams are translatable into relational tables which allows you to build
databases quickly.
• The database designer gains a better understanding of the information to
be contained in the database with the help of ER diagram.
• ER Diagram allows you to communicate with the logical structure of the
database to users.
OUTLINE
• What is ER Diagram?
• Cardinality.
• Participation.
• Exercises.
THE COMPONENTS OF AN ER DIAGRAM
▪ Attributes.
▪ Relationships.
THE COMPONENTS OF AN ER DIAGRAM: ENTITIES
Entity
• A definable thing—such as a person, place, object, concept or event—that
can have data stored about it.
• Every entity is made up of some ‘attributes’ which represent that entity.
• Think of entities as nouns
• Typically shown as a rectangle.
Examples of entities:
• Person: Employee, Student, Patient.
• Place: Store, Building.
• Object: Machine, product, and Car.
• Event: Sale, Registration, Renewal.
• Concept: Account, Course.
THE COMPONENTS OF AN ER DIAGRAM: ENTITIES
Entity type:
• A group of definable things, such as students or athletes,
whereas the entity would be the specific student or athlete.
• Other examples: customers, cars or products.
Entity set:
• Same as an entity type, but defined at a particular point in time,
such as students enrolled in a class on the first day.
• An entity set is a group of similar kind of entities.
• Other examples:
• Customers who purchased last month.
• Cars currently registered in Florida.
THE COMPONENTS OF AN ER DIAGRAM: ENTITIES
Or strong Entity
EXERCISE
Relationship
• It defines the interconnection between two entities.
• Relationship is nothing but an association among two or more entities.
• Typically shown as a diamonds.
• Entities take part in relationships.
• Think of relationships as verbs.
• There are two specific types of relationships:
▪ Strong relationship.
▪ Weak relationship.
THE COMPONENTS OF AN ER DIAGRAM: RELATIONSHIP
2. Weak relationship:
• When entity A connected with a weak relationship to entity B, the
existence of entity A depends on B entity existence.
Examples of Relationships:
• You are attending this lecture → A student attends a lecture.
Attends
Students Lecture
/takes
Is
Lecturer Lecture
giving
THE COMPONENTS OF AN ER DIAGRAM: RELATIONSHIP
Examples of Relationships:
student
descriptive attributes Undivided rectangle. with a dashed line
EXERCISE
department
course module
lecturer
student
Each department offers several courses.
offers department
course module
lecturer
student
A number of modules make up each course.
offers department
student
Students enroll in a particular course
offers department
enroll in
student
Students enroll in a particular course and take
modules towards the completion of that course
offers department
takes
enroll in
student
Each module is taught by a lecturer
offers department
takes
enroll in
student
a lecturer from the appropriate department
takes
enroll in
student
and each lecturer tutors a group of students
takes
enroll in tutors
student
THE COMPONENTS OF AN ER DIAGRAM: ATTRIBUTES
Attributes
• A property or characteristic of an entity.
• Typically shown as a an oval or circle.
• For example, a lecture might have attributes: time, date, duration, place, etc.
LecturerID
time
date
lecture
duration
place
THE COMPONENTS OF AN ER DIAGRAM: ATTRIBUTES
THE COMPONENTS OF AN ER DIAGRAM: ATTRIBUTES
OUTLINE
• What is ER Diagram?
• Cardinality.
• Participation.
• Exercises.
ER DIAGRAMS SYMBOLS & NOTATIONS
Or strong Entity
ER DIAGRAMS SYMBOLS & NOTATIONS
• There are some sub-elements which are based on main elements in
ERD Diagram.
Or strong Entity
ER DIAGRAMS SYMBOLS &
NOTATIONS
OUTLINE
• What is ER Diagram?
• Cardinality.
• Participation.
• Exercises.
Choice of Primary key for Binary
Relationship
▪ Many-to-Many relationships. The preceding union of the primary
is chosen as the primary key.
sec_course
THE COMPONENTS OF AN ER DIAGRAM: ENTITIES
Entity categories: Weak Entity
• is a type of entity that does not have any unique key for the
attribute tuples.
• Cardinality.
• Participation.
• Exercises.
CARDINALITY
• Cardinality is the degree of relationship.
• It is represented by characters “1”, “N” or “M” usually
placed at the ends of the relationships.
1 N
Instructor advisor Student
CARDINALITY
•Types of cardinal relationships:
3. Many-to-One Relationships (N:1).
Many employees may belong to one department, but one particular employee
can belong to one department only:
CARDINALITY
•Types of cardinal relationships:
3. Many-to-One Relationships (N:1).
▪ An instructor is associated with at most one student via advisor.
▪ A student is associated with several (including 0) instructors via advisor.
N 1
Instructor advisor Student
CARDINALITY
•Types of cardinal relationships:
4. Many-to-Many Relationships (M:N).
▪ One student may belong to more than one student organizations,
and one organization can admit more than one student:
CARDINALITY
•Types of cardinal relationships:
4. Many-to-Many Relationships (M:N).
▪ An instructor is associated with several (possibly 0) students via
advisor.
▪ A student is associated with several (possibly 0) instructors via
advisor.
M N
Instructor advisor Student
OUTLINE
• What is ER Diagram?
• Cardinality.
• Participation.
• Exercises.
PARTICIPATION
•Partial participation means that not all entities in the set are involved
in the relationship.
▪ e.g., not every professor guides a student (there are professors
who don’t).
OUTLINE
• What is ER Diagram?
• Cardinality.
• Participation.
• Exercises.
EXERCISES
For a bank: A customer can be a borrower for at most one loan. A loan is
associated with at most one borrower customer.
1 N
Customer borrower Loan
EXERCISES
M N
Customer borrower Loan
EXERCISES
M N
Customer borrower Loan
Construct an E-R diagram for a car
insurance company whose customers own one or
more cars each. Each car has associated with it zero
to any number of recorded accidents.
accident participated
THANK YOU