Module 2
Module 2
Skill
• Nil
Aptitude
• Ability to design ER diagram for online shopping with product
recommendation
01-Aug-24 JT 3
Data Model
• The Data Model is defined as an abstract model that organizes data
description, data semantics, and consistency constraints of data.
• The data model emphasizes on what data is needed and how it
should be organized instead of what operations will be performed on
data.
• Data Model is like an architect’s building plan, which helps to build
conceptual models and set a relationship between data items.
• The two types of Data Modeling Techniques are
• Entity Relationship (E-R) Model
• UML (Unified Modelling Language)
01-Aug-24 JT 4
Types of Data models
▪ Conceptual Data Model:
▪ This Data Model defines WHAT the system contains.
▪ This model is typically created by Business stakeholders and Data Architects.
▪ The purpose is to organize, scope and define business concepts and rules.
▪ Logical Data Model:
▪ Defines HOW the system should be implemented regardless of the DBMS.
▪ This model is typically created by Data Architects and Business Analysts.
▪ The purpose is to developed technical map of rules and data structures.
▪ Physical Data Model:
▪ This Data Model describes HOW the system will be implemented using a specific DBMS
system.
▪ This model is typically created by DBA and developers. The purpose is actual implementation
of the database.
01-Aug-24 JT 5
Types of Data Models
01-Aug-24 JT 6
Why use Data Model?
• Ensures that all data objects required by the database are accurately represented.
Omission of data will lead to creation of faulty reports and produce incorrect
results.
• A data model helps design the database at the conceptual, physical and logical
levels.
• Data Model structure helps to define the relational tables, primary and foreign
keys and stored procedures.
• It provides a clear picture of the base data and can be used by database developers
to create a physical database.
• It is also helpful to identify missing and redundant data.
• Though the initial creation of data model is labor and time consuming, in the long
run, it makes your IT infrastructure upgrade and maintenance cheaper and faster.
01-Aug-24 JT 7
E-R Modelling
Entity Relationship Model
• ER model stands for an Entity-Relationship model.
• It is a high-level data model that defines data elements and their relationship for a specified
software system.
• This model is used to define the data elements and relationship for a specified system.
Enrolment Name
Person
Relationship Attribute
Entity
Employee Works
Department
for
01-Aug-24 JT 10
Example
• Suppose we design a school database.
• In this database, the student will be an
entity with attributes like address,
name, id, age, etc.
• The address can be another entity with
attributes like city, street name, pin
code, etc and there will be a
relationship between them.
01-Aug-24 JT 11
Components/ elements of ER Model
01-Aug-24 JT 12
Entity
• An entity may be any object, class, person or place.
• In the ER diagram, an entity can be represented as rectangles.
• Consider an organization as an example- manager, product,
employee, department etc. can be taken as an entity.
01-Aug-24 JT 13
Weak Entity
• An entity that depends on another entity called a weak entity.
• The weak entity doesn't contain any key attribute of its own.
• The weak entity is represented by a double rectangle.
01-Aug-24 JT 14
Attribute
• The attribute is used to describe the property of an entity. Eclipse is
used to represent an attribute.
• For example, id, age, contact number, name, etc. can be attributes of
a student.
01-Aug-24 JT 15
Key Attribute
• The key attribute is used to represent the main characteristics of an
entity.
• It represents a primary key.
• The key attribute is represented by an ellipse with the text
underlined.
01-Aug-24 JT 16
Composite Attribute
• An attribute that composed of many other attributes is known as a
composite attribute.
• The composite attribute is represented by an ellipse, and those
ellipses are connected with an ellipse.
01-Aug-24 JT 17
Multivalued Attribute
• An attribute can have more than one value.
• These attributes are known as a multivalued attribute.
• The double oval is used to represent multivalued attribute.
• For example, a student can have more than one phone number.
01-Aug-24 JT 18
Derived Attribute
• An attribute that can be derived from
other attribute is known as a derived
attribute.
• It can be represented by a dashed
ellipse.
• For example, A person's age changes
over time and can be derived from
another attribute like Date of birth.
01-Aug-24 JT 19
Relationship
• A relationship is used to describe the relation between entities.
• Diamond or rhombus is used to represent the relationship.
01-Aug-24 JT 20
One-to-One Relationship
• When only one instance of an entity is associated with the
relationship, then it is known as one to one relationship.
• For example, A female can marry to one male, and a male can
marry to one female.
01-Aug-24 JT 21
One-to-many relationship
• When only one instance of the entity on the left, and more than one
instance of an entity on the right associates with the relationship then
this is known as a one-to-many relationship.
• For example, Scientist can invent many inventions, but the
invention is done by the only specific scientist.
01-Aug-24 JT 22
Many-to-one relationship
• When more than one instance of the entity on the left, and only one
instance of an entity on the right associates with the relationship then
it is known as a many-to-one relationship.
• For example, Student enrolls for only one course, but a course can
have many students.
•
01-Aug-24 JT 23
Many-to-many relationship
• When more than one instance of the entity on the left, and more than
one instance of an entity on the right associates with the relationship
then it is known as a many-to-many relationship.
• For example, Employee can assign by many projects and project can
have many employees.
01-Aug-24 JT 24
Mapping Constraints
• A mapping constraint is a data constraint that expresses the number
of entities to which another entity can be related via a relationship
set.
• It is most useful in describing the relationship sets that involve more
than two entity sets.
• For binary relationship set R on an entity set A and B, there are four
possible mapping cardinalities. These are as follows:
• One to one (1:1)
• One to many (1:M)
• Many to one (M:1)
• Many to many (M:M)
01-Aug-24 JT 25
Possible mapping cardinalities
One-to-One One-to-Many
1
*
Many-to-many
01-Aug-24Many-to-One JT 26
Keys
• Keys play an important role in the relational database.
• It is used to uniquely identify any record or row of data from the
table.
• It is also used to establish and identify relationships between tables.
• For example: In Student table, ID is used as a key because it is
unique for each student. In PERSON table, passport_number,
license_number, SSN are keys since they are unique for each person.
•
01-Aug-24 JT 27
Types of keys
01-Aug-24 JT 28
Primary Key
• It is the first key which is used to identify one and only one
instance of an entity uniquely.
• An entity can contain multiple keys as we saw in PERSON
table.
• The key which is most suitable from those lists become a
primary key.
• In the EMPLOYEE table, ID can be primary key since it is
unique for each employee. In the EMPLOYEE table, we can
even select License_Number and Passport_Number as
primary key since they are also unique.
• For each entity, selection of the primary key is based on
requirement and developers.
01-Aug-24 JT 29
Candidate key
• A candidate key is an attribute or set of an attribute
which can uniquely identify a tuple.
• The remaining attributes except for primary key are
considered as a candidate key.
• The candidate keys are as strong as the primary key.
• For example: In the EMPLOYEE table, id is best
suited for the primary key. Rest of the attributes like
SSN, Passport_Number, and License_Number, etc.
are considered as a candidate key.
01-Aug-24 JT 30
Super Key
• Super key is a set of an attribute which can
uniquely identify a tuple.
• Super key is a superset of a candidate key. Super Key
01-Aug-24 JT 31
Foreign key
• Foreign keys are the column of the table which is
used to point to the primary key of another table.
• In a company, every employee works in a specific
department, and employee and department are two
different entities. So, we can't store the
information of the department in the employee
table. That's why we link these two tables through
the primary key of one table.
• We add the primary key of the DEPARTMENT
table, Department_Id as a new attribute in the
EMPLOYEE table.
• Now in the EMPLOYEE table, Department_Id is
the foreign key, and both the tables are related.
01-Aug-24 JT 32
Symbols:
01-Aug-24 JT 33
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.
Entities:
01-Aug-24 JT 34
•
• Construct an E-R diagram for a car-insurance company •
Car_id
Damage type
whose customers own one or more cars each. Each car has • Owner_name
associated with it zero to any number of recorded accidents. • Date
•
•
Time
ENTITIES: • Investigating_person_id
Car: • Certifying_authority
• Car_id Car_insurance_company
• Number_plate • Car_id
• Color • Customer_id
• Model • Mebership_id
• Car_owner • Customer_name
• Car_type • Insurance type
• PUC • Renewal date
Customer • Insurance amount
• Customer_id • Accident types
• Name: fname, lname • Claiming status
• AddressAE • Certifying_authority
• Contactno • Mode_of _payment
• Car_id • Payment_status
•
•
Lincence_no
• Gender Relationship
• Date of birth • Own
• Mebership_id • Recorded/ associates
• Bank_details • memberships
• Accidents
• Location
• Accident _Type
01-Aug-24 JT 35
Constructing an ER
• Car:
Car_id Color
• Car_id
Model
• Number
• Color
• Model
• Car_owner Number Car
• Car_type
• PUC
Car_owner
PUC
Car_type
01-Aug-24 JT 36
Constructing an ER
Bank_details
• Customer Customer_id
Date _of
birth
• Customer_id Gender
• Name: fname, lname
• Address
FName
• Contactno
• Car_id Name customer
• Lincence_no
• Gender LName
• Date of birth
• Mebership_id address
Licenece_no
• Bank_details Car_id
Memebershi
p_id
01-Aug-24 JT 37
Constructing an ER
Own_b
n y 1
01-Aug-24 JT 38
Constructing an ER
01-Aug-24 JT 39
ER Practice:
Construct an E-R diagram for a hospital with a set of patients and a set
of medical doctors.
Associate with each patient a log of the various tests and examinations
conducted.
01-Aug-24 JT 40
01-Aug-24 JT 41
m
Belongs
to
Belongs
to
Teache
s
1
1
01-Aug-24 JT 42
ER Practice:
Draw the E-R diagram which models an online bookstore.
01-Aug-24 JT 43
01-Aug-24 JT 44
Example
A university registrar’s office maintains data about the following entities:
1. courses, including number, title, credits, syllabus, and prerequisites;
2. course offerings, including course number, year, semester, section
number, instructor(s), timings, and classroom;
3. students, including student-id, name, and program;
4. instructors, including identification number, name, department, and title.
5. 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.
01-Aug-24 JT 45
01-Aug-24 JT 46
Extended Entity-Relationship
(EER) Model
EER model
• The extended E-R features
• Specialization
• Generalization
• Higher- and lower-level entity sets
• Attribute inheritance
• Aggregation.
01-Aug-24 JT 48
Consider…
• Database schema example “UNIVDERSITY DATABASE”
• Entity PERSON with attributes ID, NAME, ADDRESS
01-Aug-24 JT 49
Specialization
Specialization
• An entity set may include subgroupings of entities that are distinct in
some way from other entities in the set.
• For instance, a subset of entities within an entity set may have attributes
that are not shared by all the entities in the entity set.
• The E-R model provides a means for representing these distinctive entity
groupings.
• The process of designating subgroupings within an entity set is called
specialization.
• The entity set person may be further classified as one of the following:
• employee.
• student.
01-Aug-24 JT 51
Specialization
• Each of these person types is described by a set of attributes that
includes all the attributes of entity set person plus possibly additional
attributes.
• For example, employee entities may be described further by the
attribute salary, whereas student entities may be described further by
the attribute tot cred.
• The specialization of person allows us to distinguish among person
entities according to whether they correspond to employees or
students: in general, a person could be an employee, a student, both,
or neither.
01-Aug-24 JT 52
Specialization
• In terms of an E-R diagram, specialization is depicted by a hollow
arrow-head pointing from the specialized entity to the other entity.
• This relationship is referred as the ISA relationship, which stands for
“is a” and represents
• instructor isa employee
01-Aug-24 JT 53
Specialization
▪ The way we depict specialization in an E-R diagram depends on whether an entity may belong
to multiple specialized entity sets or if it must belong to at most one specialized entity set.
▪ The former case (multiple sets permitted) is called overlapping specialization, while the latter
case (at most one permitted) is called disjoint specialization.
▪ For an overlapping specialization (as is the case for student and employee as specializations of
person), two separate arrows are used.
▪ For a disjoint specialization (as is the case for instructor and secretary as specializations of
employee), a single arrow is used.
▪ The specialization relationship may also be referred to as a superclass-subclass relationship.
▪ Higher and lower order entity sets are depicted as regular entity sets—that is, as rectangles
containing the name of the entity set.
01-Aug-24 JT 54
01-Aug-24 JT 55
Example
Students Employee
• Graduate • Instructor
• ID, • id
• name, • name
• address, and • salary
• tot cred. • rank
• residential_college
• Undergraduate • Secretory
• ID, • id
• name, • name
• address, and • Salary
• tot cred. • hours_per_week
• Office_number • secretory_for
01-Aug-24 JT 56
Overlapping
Disjoint
01-Aug-24 JT 57
Generalization
Generalization
• There are similarities between the instructor entity set and the secretary entity set in the
sense that they have several attributes that are conceptually the same across the two
entity sets: namely, the identifier, name, and salary attributes.
• This commonality can be expressed by generalization, which is a containment
relationship that exists between a higher-level entity set and one or more lower-level
entity sets.
• In our example, employee is the higher-level entity set and instructor and secretary are
lower-level entity sets. In this case, attributes that are conceptually the same had different
names in the two lower-level entity sets.
• To create a generalization, the attributes must be given a common name and represented
with the higher-level entity person.
01-Aug-24 JT 59
Generalization
• The refinement from an initial entity set into successive levels of entity
subgroupings represents a top-down design process in which distinctions
are made explicit.
• The design process may also proceed in a bottom-up manner, in which
multiple entity sets are synthesized into a higher-level entity set on the
basis of common features.
• The database designer may have first identified:
• instructor entity set with attributes instructor id, instructor name, instructor salary,
and rank.
• secretary entity set with attributes secretary id, secretary name, secretary
salary,and hours per week.
01-Aug-24 JT 60
Generalization
• Higher- and lower-level entity sets also may be designated by the terms superclass and
subclass, respectively.
• The person entity set is the superclass of the employee and student subclasses.
• Generalization is a simple inversion of specialization.
• In terms of the E-R diagram itself, do not distinguish between specialization and
generalization.
• New levels of entity representation are distinguished (specialization) or synthesized
(generalization) as the design schema comes to express fully the database application and the
user requirements of the database.
• Differences in the two approaches may be characterized by their starting point and overall
goal.
01-Aug-24 JT 61
Specialization Generalization
• Specialization stems from a single • Generalization proceeds from the
entity set; it emphasizes differences recognition that several entity sets share
among entities within the set by some common features (namely, they are
creating distinct lower-level entity sets. described by the same attributes and
• These lower-level entity sets may have participate in the same relationship sets).
attributes, or may participate in • Based on their commonalities,
relationships, that do not apply to all the generalization synthesizes these entity sets
entities in the higher-level entity set. into a single, higher-level entity set.
• Generalization is used to emphasize the
similarities among lower-level entity sets
and to hide the differences; it also permits
an economy of representation in that
shared attributes are not repeated.
01-Aug-24 JT 62
Aggregation
Aggregation
• An ER diagram is not capable of representing the relationship
between an entity and a relationship which may be required in some
scenarios.
• In those cases, a relationship with its corresponding entities is
aggregated into a higher-level entity.
• Aggregation is an abstraction through which we can represent
relationships as higher-level entity sets.
01-Aug-24 JT 64
Aggregation Example
▪ For example: Center entity offers the Course entity act as a single entity in the
relationship which is in a relationship with another entity visitor.
▪ In the real world, if a visitor visits a coaching center, then he will never enquiry
about the Course only or just about the Center instead he will ask the enquiry about
both.
65
01-Aug-24 JT 66
Short answer Questions
• Define Entity, Entity Set, and extensions of entity set. Give one example for
each?
• Define and give examples to illustrate the four types of attributes in database?
• Define relationship and participation?
• Define mapping cardinality or cardinality ratio?
• Explain the four types of mapping cardinality with example?
• Define weak Entity set. Give an example and explain why it is weak entity set?
• Define discriminator or partial key of a weak entity set. Give example?
01-Aug-24 JT 67
Long answer questions
• Explain about various data models
• Give example of following relationships : (i) Many-to-One (ii) One-
to-One (iii) One-to-Many (iv) Many-to-Many
• Discuss with examples about various types of attributes present in
the ER model.
• What are the different types of attributes? Explain with example.
• Draw ER diagram for the given case study (Refer case study samples
discussed.)
01-Aug-24 JT 68
Thank
You