0% found this document useful (0 votes)
15 views

E R Model (Unit 1)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

E R Model (Unit 1)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 79

Dr. Kuldeep N.

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

❑ A database can be modeled as:


▪ a collection of entities,
▪ relationship among entities.
❑ An entity is an object that exists and is distinguishable from other objects.
▪ Example: specific person, company, event, plant
❑ Entities have attributes
▪ Example: people have names and addresses
❑ An entity set is a set of entities of the same type that share the same properties.
▪ Example: set of all persons, companies, trees, holidays
ER MODEL BASICS

▪ Entities (objects): Any thing that may have an


independent existence and distinct from other entities
based on their attributes.
• e.g. Customers, Accounts, Trainee, Student etc.
▪ Attributes: Properties/characteristics that describe a
entity.
• e.g.: Student Name, DOB, Address, etc.
▪ Relationships: Associations between entities.
• e.g. Account A-101 is held by customer Johnson etc.
ER MODELING - NOTATIONS
Entities & Attributes

• 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

• A database usually contains groups of entities that are similar.

• 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

▪ Attribute describe the property of entity and

relationship.

▪ The set of possible values for an attribute is called the

domain of the attribute.

• 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

Types of Attributes Definition Example


Simple attribute Cannot be divided into simpler Gender of the
components employee

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

Multi-valued Can take up many values Skill set of the


employee

Stored Attribute Attribute that need to be stored Date of joining of the


permanently employee

Derived Attribute Attribute that can be calculated Years of service of the


based on other attributes. employee
1. Composite versus Simple (Atomic) Attributes

• 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.

• For example, Age is a single-valued attribute of a person.

• 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

• Combination of multivalued and composite attributes.


• Address can be a complex attribute.
Key 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

▪ A group of one or more attributes that uniquely identify an entity in


the entity set.
▪ i.e. the attribute (or combination of attributes) that is unique for
every entity instance.
▪ e.g.: the account number of an account, the employee id of an
employee etc.
ATTRIBUTES NOTATIONS
ER MODELING - EXAMPLE
Entity Types

▪ Regular Entity: Entity that has its own key attribute


(s).
• e.g.: Employee, student ,customer, policy holder etc.

▪ Weak entity: Entity that depends on other entity for


its existence and doesn’t have key attribute (s) of its
own.
• e.g. : spouse of employee
WEAK ENTITY SETS

❑ 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

❑ Refers to number of entity sets that participate in 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.

❑ Relationship sets may involve more than two entity sets.

❑ Relationships between more than two entity sets are rare. Most relationships are binary.
(More on this later.)
Degree of a Relationship

▪Degree: Express the number of entity sets associated (Participated)


in relationship set.
• One Unary
• Two Binary
• Three Ternary

▪ 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.

• E.g. : Some instances of employee manage other instances of Employee.


• E.g.: person is married to person.
UNARY RELATIONSHIP

Unary Relationship

Role names may be added to make the meaning more explicit


BINARY RELATIONSHIP

Binary Relationship

A relationship between two entity types


TERNARY RELATIONSHIP

Ternary Relationship

A relationship connecting three entity types.


MAPPING CARDINALITIES/CARDINALITY RATIO

• 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

▪ Express the number of entities to which other


entities can be related via a relationship.

▪ (What is the maximum number of relationship in


which an entity can participate with another
entity)

▪ It is useful in describing relationship set of any


degree.
Types Of Cardinality

• One-to-One (1:1)
• One-to-Many (1:N)
• Many to One (M:1)
• Many to Many (M:N)
Mapping Cardinality

One to one One to many


Mapping Cardinality

Many to one Many to many


ONE-TO-ONE (1:1)

One entity from entity set A


can be associated with at
most one entity of entity set
B and vice versa.
For example, one Student can
have only one college ID at a
time.

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)

One entity from entity set A


can be associated with
multiple entities of entity set
B, but an entity from entity set
B can be associated with at
most one entity.
For example, one class is
consisting of multiple
students.

Note: Some elements in A and B may not be mapped to any elements in the other set
MANY TO ONE (M:1)

More than one entity from entity set A


can be associated with at most one entity
of entity set B. However, an entity from
entity set B may or may not be associated
with more than one entity from entity set
A.
For example, many students belong to
the same class.

Note: Some elements in A and B may not be mapped to any elements in the other set
Example:
Many To One Binary Relationship

Many employees work in a single department. Hence Many to One


binary relationship where many employees works in one department.
MANY TO MANY (M:N)

One entity from set A can be


associated with more than one
entity from B and vice versa.
For example, Students as a group are
associated with multiple faculty
members, and faculty members can be
associated with multiple students.

Note: Some elements in A and B may not be mapped to any elements in the other set
MANY-TO-MANY RELATIONSHIP

• A customer is associated with several (possibly 0) loans via borrower


• A loan is associated with several (possibly 0) customers via borrower
Example:
Many To Many Binar y 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

▪ Participation constraint specifies the existence of an entity when it is


related to another entity in a relationship.
▪ (Minimum number of relationship an enetity can participate)
▪ Minimum Cardinality: It defines minimum number of times an entity in an entity set
participates in a relationship.
▪ Maximum Cardinality: It defines maximum number of times an entity in an entity
set participates in a relationship.

M N
Movie
(1,8)
has Actor
(0,4)
T.P. P.P.
TYPES OF PARTICIPATION
CONSTRAINT

▪ There are two 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

Employee Head-of Department


• Employee: partial
• Department: total

▪ 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

These attributes best describe the relationship prescription rather than


any individual entity Doctor, Patient or Medicine.
IDENTIFYING 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

Bank Information System


ER MODELING - NOTATIONS

An Entity can be defined as an object or concept


about which user wants to store information.

A weak Entity requires another Entity for it’s


existence. Example Order Item depends upon Order
Number for its existence. Without Order Number it is
impossible to identify Order Item uniquely.

Properties or characteristics of an Entity is called


Attributes of entity.

If an attribute is the unique or distinguishing


characteristic of the Entity it is called Key Attribute

If an attribute can have more than one value then it


is called multi-valued attribute.

For example, an employee Entity can have multiple


skill values.
Copyright © 2008, Infosys Technologies Ltd. 47 Confidential
ER MODELING - NOTATIONS

If the value of an attribute can be derived from


another attribute it is called derived attribute. For
example, an employee's monthly salary is based on
the employee's basic salary and House rent
allowance.

Relationships in ER Diagram illustrate how two


entities of database share information.

We connect a weak entity through a strong entity


using a weak relationship notation.
ER MODELING - EXAMPLE

On Line Book Shop


SUMMARY OF SYMBOLS USED IN
E-R NOTATION
E-R Diagram Notations:
How to Draw an ER Diagram:
1) First, identify all the Entities. Embed all the entities in a rectangle and label them
properly.
2) Identify relationships between entities and connect them using a diamond in the
middle, illustrating the relationship. Do not connect relationships with each other.
3) Connect attributes for entities and label them properly.

4) Eradicate any redundant entities or relationships.

5) Make sure your ER Diagram supports all the data provided to design the
database.

6) Effectively use colors to highlight key areas in your diagrams.


Generalization:
• It works on the principle of bottom up approach. In Generalization lower level
functions are combined to form higher level function which is called as entities. This
process is repeated further to make advanced level entities.

• 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:

• Construct an ER diagram of customer account of customer account relationship.


• Customer entity with attributes SS#, customer_name, street, customer_city, and account entity
with attributes account_no, and balance.
• The customer account relationship with date attributes.
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.

You might also like