1.3 ER Diagram, Extended ER Diagram

Download as pdf or txt
Download as pdf or txt
You are on page 1of 46

Day 2 & Day 3- Agenda

Day 2
ER Diagram

Components of
ER Diagram

Entity and
Attributes
Relationships
and constraints
Entity Relationship Diagram- Introduction
ER Model describes the structure of a database with the help of Entity Relationship Diagram (ER Diagram)

Peter Chen ER Diagram ER Diagram ER Diagram


proposed the
ER Diagram in represents helps you to
design or
1971 to create real-world analyze data
blueprint of a
a uniform entities and requirements
database that
convention the systematically
can later be
that can be relationship to produce a
implemented
used for between well-designed
as a database
relational them database
databases and
networks.
Components of ER Diagram
ER diagram depends on below three concepts: • Entity • Attributes • Relationships
Entity and Attributes
An entity set is a group of similar kind of entities

Examples of
Entities Attributes
• Person: Employee,
Student, Patient
• describes the property
• Place: Store, Building
• Object: Machine, product,
of an entity
and Car • represented as Oval
• Event: Sale, Registration, • single-valued property
Renewal of either an entity-type
• Concept: Account, Course. or a relationship-type
Weak Entity

An entity that cannot be uniquely identified by its own attributes relies on the relationship with
other entity represented by a double-rectangle

bank account cannot be uniquely identified without knowing the bank to which the account
belongs, so bank account is a weak entity

An entity that
cannot be
uniquely Sample text goes
identified by its here, replace it
own attributes with your own
• relies on the text.
relationship with
other entity
• represented by
a double-
rectangle
SAMPLE TEXT
MCQ - Entity
1. In an ER diagram, how is an entity represented?
a) As a rectangle with rounded corners
b) As a circle
c) As a line connecting two rectangles
d) As a diamond shape
2. In the ER model, what is an attribute of an entity?
a) A relationship between entities
b) A property or characteristic of the entity
c) A constraint on the entity
d) A foreign key
3. Which of the following is an example of an entity in a university database?
a) Student
b) GPA
c) Class time
d) Department
MCQ - Entity
4. In an ER diagram, what does a double oval around an entity represent?
a) A weak entity
b) A strong entity
c) An attribute
d) A composite entity
5. What is a weak entity in the ER model?
a) An entity with no attributes
b) An entity that depends on another entity for identification
c) An entity that is not allowed in the database schema
d) An entity with a composite primary key
MCQ- Answer
1. a) As a rectangle with rounded corners
2. b) A property or characteristic of the entity
3. a) Student
4. a) A weak entity
5. b) An entity that depends on another entity for identification

Quiz 6
Types of Attributes

Simple

Derived
Types of
Composite
Attributes

Single & Multi


valued
Attributes

can't be divided any An attribute composed of many Holds a single value for a
further into subparts other attributes is called a particular entity
It is an atomic value composite attribute and they For example:
For example, are further divided into a tree-
• Student roll number like structure. Every node is Student roll no
• Bank account number then connected to its attribute
• contact number

22CS001
Attributes

Multivalued attributes can •The value for this type of


have more than one attribute can be derived from
values the values of other related
Multivalued attributes are attributes or entities
depicted by a double •Derived attributes are
ellipse. depicted by a dashed ellipse.
For example: • For example:
• Mobile Number •Age (can be derived from
• Email address DOB)
Attribute representation
Quick 5 - Attributes
Identify the different types of Attributes in the below picture.

Quiz 5
Quick 5 - Answer
Identify the different types of Attributes in the below picture.

Simple – Roll_No
Single – DOB
Quiz 6 Multivalued – Phone-No
Composite – Address
Derived - Age
Relationships and Constraints
shows the relationship among entities and it is represented using a diamond shape

Relationship Constraints
• It is an association
among two or more ✓ MAPPING
entities. CARDINALITIES
• We can often identify
relationships with verbs ✓ PARTICIPATION
or verb phrases. CONSTRAINTS
• All the entities
(rectangles) participating
in a relationship, are
connected to it by a line.
Constraints – Mapping Cardinalities
Defines the numerical attributes of the relationship between two entities or entity sets

The number of times an entity of an


It expresses the number of entities
entity set participates in a relationship
to which another entity can be
set is known as cardinality
associated via a relationship set

One to One Many to One

One to Many Many to Many


02
Mapping Cardinalities

One to One

✓ When each entity in ✓ When more than one


each entity set can instance of an entity is
take part only once in associated with a
the relationship, the relationship.
cardinality is one to ✓ When a single instance
one. One to Many of an entity is
✓ When a single instance associated with more
of an entity is than one instance of
associated with a another entity
single instance of
another entity
Mapping Cardinalities

Many to One
✓ When more than one
instances of an entity is
✓ When more than one
associated with more
instance of an entity is
than one instances of
associated with a
another entity
single instance of
✓ When entities in all
another entity.
entity sets can take part
✓ When more than one Many to Many more than once in the
instance of an entity is
relationship cardinality is
associated with the
many to many
relationship
Participation Constraints

✓ The participation of an entity set E in a


relationship set R is said to be total if
every entity in E participates in at least
one relationship in R.
✓ If only some entities in E participate in
relationships in R, the participation of
entity set E in relationship R is said to Examples
be part
Cardinality Notations to be used for ER Diagram
Match the Following - Relationships
1.One-to-One (1:1) Relationship - A. Each entity in the relationship can be associated with multiple instances of the
other entity.
2.One-to-Many (1:N) Relationship - B. Each entity in the relationship can be associated with only one instance of the
other entity.
3.Many-to-Many (N: N) Relationship - C. A relationship where one entity can be associated with only one instance of
another entity.
4.Cardinality - D. A relationship where multiple entities can be associated with multiple instances of each other.
5.Foreign Key - E. A numeric value specifies the number of instances of one entity that can be associated with
another entity in a relationship.
6.Referential Integrity - F. A key that establishes a link between two tables, typically the primary key of one table that
appears as an attribute in another table.
Match - Answer
1.C. Each entity in the relationship can be associated with only one instance of the other entity.

2.A. Each entity in the relationship can be associated with multiple instances of the other entity.

3.D. A relationship where multiple entities can be associated with multiple instances of each other.

4.E. A numeric value that specifies the number of instances of one entity that can be associated with another
entity in a relationship.

5.F. A key that establishes a link between two tables, typically the primary key of one table that appears as an
attribute in another table.

6.B. A relationship where one entity can be associated with only one instance of another entity.
Quick 6 - Constraints
Consider a university database with two tables: "Students" and "Courses." There is a one-to-many relationship
between students and courses, where each student must be enrolled in at least one course.

Quiz 6
Quick 6 - Answer
Total participation means that every entity in one entity set must participate in a relationship with an entity in
another entity set.

Suppose we have two students, Alice and Bob, in the "Students" table. To enforce total participation, the
database ensures that both Alice and Bob are associated with at least one course in the "Courses" table. For
example, Alice is enrolled in "Math 101," and Bob is enrolled in "History 201."

Quiz 6
Steps to Create an ERD
Follow the steps given below to draw an ER model

01
Identify the
02
entity sets Identify the
Relationship

Complete
the ER
ER 03
Diagram
Identify
06 Diagram the Key
Attributes

Identify the
attributes Map the04
05 Cardinalities
Example1 – ER Diagram
In a university, a Student enrolls in Courses. A student must be assigned to at least one or
more Courses. Each course is taught by a single Professor. To maintain instruction quality, a
Professor can deliver only one course
Identify the Entity

Identify the Relationships


Example1 – ER Diagram

Identify the Cardinality

Identify the Attributes


Examples – ER Diagram

Complete the ER Diagram


Example2 – ER Diagram
(a) 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.

Schema:
Car insurance tables: person (driver-id, name, address)
car (license, year,model)
accident (report-number, date, location)
participated(driver-id, license, report-number, damageamount)
Example2 – ER Diagram
(a) 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.
Example3 – ER Diagram
Suppose you are given the following requirements for a simple database for the National
Hockey League (NHL): the NHL has many teams, each team has a name, a city, a coach, a
captain, and a set of players, each player belongs to only one team, each player has a name, a
position (such as left wing or goalie), a skill level, and a set of injury records, a team captain is
also a player, a game is played between two teams (referred to as host_team and guest_team)
and has a date (such as May 11th, 1999) and a score (such as 4 to 2). Construct a clean and
concise ER diagram for the NHL database.
Example3– ER Diagram
Example4 – ER Diagram
A university registrar’s office maintains data about the following entities: courses, including
number, title, credits, syllabus, and prerequisites; course offerings, including course number,
year, semester, section number, instructor(s), timings, and classroom; students, including
student-id, name, and program; instructors, including identification number, name,
department, and title. Further, the enrollment of students in courses and grades awarded to
students in each course they are enrolled for must be appropriately modeled. Construct an E-R
diagram for the registrar’s office. Document all assumptions that you make about the mapping
constraints.
Example4– ER Diagram
Case Study
Given the E-R Diagram below, describe the database and the constraints that apply to it.

Quiz 6
Case Study - Answer
The model is about horse racing. There are horses and there are races. Races take place at

tracks.

A horse may run in many races and a number of races may be run at the same track.

The primary key of each entity may now be identified.

We assume the relationship “Ran” is many-to-many. Is the relationship “Held at” many-to-
many? If we assume
Quiz 6 that the PK of Race is “Race No” then the same race cannot be held at two
different tracks and therefore “Held at” is one-to-many.
Enhanced ER Model

Generalization
Three new
concepts Specialization

Aggregation
Generalization
● bottom-up approach
● two lower level entities combine to form a higher level entity
● It's more like Superclass and Subclass system
● entities are combined to form a more generalised entity, in other words,
sub-classes are combined to form a super-class.
Saving and Current account types
entities can be generalised and an entity
with name Account can be created,
which covers both
Specialization
● opposite to Generalization
● top-down approach
● one higher level entity can be broken down into two lower level entity
Aggregation
● ER diagram is not capable of representing relationship between an entity and a
relationship
● A relationship with its corresponding entities is aggregated into a higher level
entity
● Aggregation is a process when relation between two entities is treated as a
single entity
● Aggregation is an abstraction through which relationships are treated as higher-
level entities
Center and Course together, is acting as an Entity,
which is in relationship with another entity Visitor.
Now in real world, if a Visitor or a Student visits a
Coaching Center, he/she will never enquire about the
center only or just about the course, rather he/she will
ask enquire about both.

You might also like