E R Model (Unit 1)
E R Model (Unit 1)
Tripathi
Assistant Professor
CSE
Database Management System (DBMS)
Data Base Management System
ER-MODELLING- BASICS
CONTENT
▪ ER Model Basics
• Entity
• Entity Type
• Attribute
• Attribute Type
• Key and Key Attributes
• Relationship
• ER Diagram Example
Introduction E-R (Entity-Relationship)
Data Model
• The basic concept that the ER model represents is an entity, which is a thing or object in the
real world with an independent existence.
• An entity may be an object with a physical existence (for example, a particular person, car,
house, or employee) or it may be an object with a conceptual existence (for instance, a
company, a job, or a university course).
• Each entity has attributes—the particular properties that describe it. For example, an
EMPLOYEE entity may be described by the employee’s name, age, address, salary, and job. A
particular entity will have a value for each of its attributes.
Entity And Entity Set
▪ Entity:
• Real-world object distinguishable from other objects.
• E.g. customers, accounts, bank branch
▪ Entity Set:
• A collection of similar entities. E.g. Students, courses,
Teachers, Departments
Entity types and Entity Sets
• For example, a company employing hundreds of employees may want to store similar
information concerning each of the employees. These employee entities share the same
attributes, but each entity has its own value(s) for each attribute.
• An entity type defines a collection (or set) of entities that have the same attributes.
• Each entity type in the database is described by its name and attributes.
• Figure below shows two entity types: EMPLOYEE and COMPANY, and a list of some of the
attributes for each. A few individual entities of each type are also illustrated, along with the
values of their attributes. The collection of all entities of a particular entity type in the
database at any point in time is called an entity set or entity collection; the entity set is
usually referred to using the same name as the entity type, even though they are two
separate concepts.
Entity types and Entity Sets
ATTRIBUTES
• An entity is represented by a set of attributes, that is descriptive properties possessed by all members of an
entity set.
Example:
customer = (customer-id, customer-name,
customer-street, customer-city)
loan = (loan-number, amount)
• Domain – the set of permitted values for each attribute
• Attribute types:
• Simple and composite attributes.
• Single-valued and multi-valued attributes
• E.g. multivalued attribute: phone-numbers
• Derived attributes
• Can be computed from other attributes
• E.g. age, given date of birth
Attributes
relationship.
• e.g.: The domain of attribute “marital status” is having four values: single, married,
divorced or widowed.
• e.g. :The domain of the attribute “month” is having twelve values ranging from
January to December.
Attributes Types
Address of the
Composite attribute Can be split into components
employee
Can take on only a single value
Single valued Age of the employee
for each entity instance
• Composite attributes can be divided into smaller subparts, which represent more basic attributes with independent
meanings.
• For example, the Address attribute of the EMPLOYEE entity can be subdivided into Street_address, City, State, and Zip.
• Simple or atomic attributes: Attributes that are not divisible are called simple or atomic attributes.
• The value of a composite attribute is the concatenation of the values of its component simple attributes.
• If the composite attribute is referenced only as a whole, there is no need to subdivide it into component attributes. For
example, if there is no need to refer to the individual components of an address (Zip Code, street, and so on), then the
whole address can be designated as a simple attribute.
COMPOSITE ATTRIBUTE EXAMPLE
Composite attribute
Represented by an ellipse from which other ellipses emanate and represent the
component attributes. E.g Address
Composite Attributes
Composite attribute
2. Single-Valued versus Multivalued Attributes
• Single-valued Attributes: Most attributes have a single value for a particular entity; such attributes are called single-
valued.
• Multivalued attribute: In some cases an attribute can have a set of values for the same entity, known as multivalued
attribute.
• For example: one person may not have any Mobile number, another person may have one, and a third person may
have two or more Mobile number; therefore, different people can have different numbers of values for the
Mobile_number attribute. Such attributes are called multivalued.
• A multivalued attribute may have lower and upper bounds to constrain the number of values allowed for each
individual entity.
3. Stored versus Derived Attributes
• In some cases, two (or more) attribute values are related—for example, the Age and Birth_date attributes of a
person. For a particular person entity, the value of Age can be determined from the current (today’s) date and the
value of that person’s Birth_date.
• The Age attribute is hence called a derived attribute and is said to be derivable from the Birth_date attribute, which
is called a stored attribute.
• Some attribute values can be derived from related entities; for example, an attribute Number_of_employees of a
DEPARTMENT entity can be derived by counting the number of employees related to (working for) that department.
4. Complex Attributes
• We must have a way to specify how tuples within a given relation are distinguished.
• This is expressed in terms of their attributes. That is, the values of the attribute values of a tuple
must be such that they can uniquely identify the tuple.
• In other words, no two tuples in a relation are allowed to have exactly the same value for all
attributes.
Key Attributes
❑ An entity set that does not have a primary key is referred to as a weak entity set.
❑ Weak entity is owned by strong entity.
❑ A weak entity always has a total participation in a identifying relationship.
❑ The existence of a weak entity set depends on the existence of a identifying entity set
❖ it must relate to the identifying entity set via a total, one-to-many relationship set from the identifying to the
weak entity set
❖ Identifying relationship depicted using a double diamond
❑ The discriminator (or partial key) of a weak entity set is the set of attributes that distinguishes among all the entities of
a weak entity set.
❑ The primary key of a weak entity set is formed by the primary key of the strong entity set on which the weak entity
set is existence dependent, plus the weak entity set’s discriminator.
WEAK ENTITY SETS (CONT.)
• We depict a weak entity set by double rectangles.
• We underline the discriminator of a weak entity set with a dashed line.
• payment-number – discriminator of the payment entity set
• Primary key for payment – (loan-number, payment-number)
Relationship And Relationship Set
▪ Relationship
• Association among two or more entities. i.e. Any entity can be
related to other entities via relationships.
e.g.: A supplier may supply some part.
Degree Of A Relationship, Mapping Cardinality And
Participation Constraint
▪ Degree of a Relationship
• Unary Relationship
• Binary Relationship
• Ternary Relationship
▪ Mapping Cardinality
▪ Participation Constraint
▪ The Relationship Type has these main Components:
1. Name of a relationship
2. Degree of a Relationship
3. Mapping Cardinality
4. Participation Constraints.
DEGREE OF A
RELATIONSHIP SET
❑ Relationship sets that involve two entity sets are binary (or degree two). Generally, most
relationship sets in a database system are binary.
❑ Relationships between more than two entity sets are rare. Most relationships are binary.
(More on this later.)
Degree of a Relationship
▪ e.g.:
1.employee manager-of employee is unary.
2.employee works-for department is binary.
3.Customer purchases items from a shop keeper.
• Here customer purchase item, shop keeper is a ternary relationship
UNARY RELATIONSHIP
Unary Relationship
• A unary relationship is represented as a diamond which connects one entity to itself as a loop.
Unary Relationship
Binary Relationship
Ternary Relationship
• Express the number of entities to which another entity can be associated via a relationship set.
• Most useful in describing binary relationship sets.
• For a binary relationship set the mapping cardinality must be one of the following types:
1. One to one
2. One to many
3. Many to one
4. Many to many
Mapping Cardinality
• One-to-One (1:1)
• One-to-Many (1:N)
• Many to One (M:1)
• Many to Many (M:N)
Mapping Cardinality
Note: Some elements in A and B may not be mapped to any elements in the other set
Example:
One To One Binary Relationship
Each employee only has a single ID card. Hence this is a One to One binary
relationship where One employee has One ID card.
ONE-TO-MANY (1:N)
Note: Some elements in A and B may not be mapped to any elements in the other set
MANY TO ONE (M:1)
Note: Some elements in A and B may not be mapped to any elements in the other set
Example:
Many To One Binary Relationship
Note: Some elements in A and B may not be mapped to any elements in the other set
MANY-TO-MANY RELATIONSHIP
A book can have many authors or multiple authors may have written a single
book.
So, there is a Many to Many relationship between books and authors as Many
books have many authors.
Participation Constraint
M N
Movie
(1,8)
has Actor
(0,4)
T.P. P.P.
TYPES OF PARTICIPATION
CONSTRAINT
1. Total Participation: Each entity in the a entity set connected through the relationship to at
least one entity in the other participating entity set. In other words, Every entity in an entity set
participate in relationship.
2. Partial Participation : In any entity set if at least one entity is such type that it doesn’t
participate in the relationship, then this type of participation of entity set is known as Partial
Participation. In other words, Each entity in entity set may or may not occur in at least one
relationship in a relationship set.
PARTICIPATION OF AN ENTITY SET
IN A RELATIONSHIP SET
Total participation (indicated by double line): every entity in the entity set participates in at least
one relationship in the relationship set
E.g. participation of loan in borrower is total
every loan must have a customer associated to it via borrower
Partial participation: some entities may not participate in any relationship in the relationship set
E.g. participation of customer in borrower is partial
EXAMPLE
▪ All employees will not be head-of some department. So only few instances of employee
entity participate in the above relationship. But each department will be headed by some
employee.
▪ So department entity’s participation is total and employee entity’s participation is partial in the
above relationship.
RELATIONSHIP SETS WITH
ATTRIBUTES
• Similar to entity a relationship can also have some attributes to best describe the
given relationship.
• We generally try to avoid attributes with relationship.
RELATIONSHIP SETS WITH
ATTRIBUTES
Attributes of a Relationship
• The identifying relationship is the one which relates the weak entity (dependant) with the strong entity (Employee) on which it
depends.
• Used for identifying a weak entity.
• Id is underlined with a dotted line because it is used to form composite key of dependent entity along with E#.
Identifying Relationship
E-R DIAGRAM WITH A TERNARY
RELATIONSHIP
ER MODELING - EXAMPLE
5) Make sure your ER Diagram supports all the data provided to design the
database.
• A bottom-up design process – combine a number of entity sets that share the same features into a
higher-level entity set.
• Specialization and generalization are simple inversions of each other; they are represented in an E-R
diagram in the same way.
• The terms specialization and generalization are used interchangeably.
Generalization:
Specialization:
• We can say that Specialization is opposite of Generalization. In Specialization things
are broken down into smaller things to simplify it further. We can also say that in
Specialization a particular entity gets divided into sub entities and it’s done on the
basis of it’s characteristics. Also in Specialization Inheritance takes place.
• Top-down design process; we designate subgroupings within an entity set that are distinctive from
other entities in the set.
• These subgroupings become lower-level entity sets that have attributes or participate in
relationships that do not apply to the higher-level entity set.
• Depicted by a triangle component labeled ISA (E.g. customer “is a” person).
• Attribute inheritance – a lower-level entity set inherits all the attributes and relationship
participation of the higher-level entity set to which it is linked.
Specialization:
Specialization Example:
Difference between Generalization and Specialization:
Aggregation:
• Aggregation refers to the process by which entities are combined to form a single meaningful
entity. The specific entities are combined because they do not make sense on their own. To establish
a single entity, aggregation creates a relationship that combines these entities.
• In aggregation, the relation between two entities is treated as a single entity. In aggregation,
relationship with its corresponding entities is aggregated into a higher level entity.
Aggregation:
• 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.
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.
E-R Diagram Example:
• Construct an ER Diagram for Company having following details :
a) Company organized into DEPARTMENT. Each department has unique name and a particular
employee who manages the department. Start date for the manager is recorded. Department may
have several locations.
b) A department controls a number of PROJECT. Projects have a unique name, number and a single
location.
c) Company’s EMPLOYEE name, ssno, address, salary, sex and birth date are recorded. An employee
is assigned to one department, but may work for several projects (not necessarily controlled by
her dept). Number of hours/week an employee works on each project is recorded; The immediate
supervisor for the employee.
d) Employee’s DEPENDENT are tracked for health insurance purposes (dependent name, birthdate,
relationship to employee).
E-R Diagram Example Solution:
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.
Construct an E-R diagram for a students, course, teacher relationship.
ER diagram for a UNIVERSITY database schema
E-R Diagram Example:
• A university database contains information about professors (identified by social security number) and
courses (identified by courseid), professors teach courses; each of the following situations concerns the
teaches relationship set.
For each situation draw an E-R diagram:
(i) Professors can teach the same course in several semesters and each offering must be recorded.
(ii) Professors can teach the same course in several semesters, and only the most recent such offering needs to
be recorded.
(iii) Every Professor must teach some course.
(iv) Every Professor teaches exactly one course.
(v) Every Professor teaches exactly one course and every course must be taught by some professor.