DBMS
UNIT 2
E-R Model
Varsha Nemade
24/11/10
[Link] Nemade
Entity-Relationship (E/R) Model
Widely used conceptual level data model
Data model to describe the database system at the
requirements collection stage
•high level description.
•easy to understand for the enterprise managers.
•rigorous enough to be used for system building
Concepts available in the model
•entities and attributes of entities.
•relationships between entities.
•diagrammatic notation. 2
24/11/10
[Link] Nemade
Entities
Entity-
A thing of independent physical or conceptual existence and
distinguishable.
In the University database context, an individual
student, faculty member, a class room, a course are entities.
Entity Set or Entity Type-
Collection of entities all having the same properties.
Student entity set –collection of all student entities.
Course entity set –collection of all course entities.
24/11/10
[Link] Nemade
Entity Sets customer
and loan
customer-id customer- customer- customer- loan- amount
name street city number
24/11/10
[Link] Nemade
Attributes
Each entity is described by a set of attributes/properties.
student entity
Stud Name–name of the student.
Roll Number–the roll number of the student
Sex–the gender of the student etc.
All entities in an Entity set/type have the same set of
attributes.
Chosen set of attributes –amount of detail in modeling.
24/11/10
[Link] Nemade
Types of Attributes
•Simple Attributes
having atomic or indivisible values.
example: Department–a string
•Composite Attributes
having several components in the value.
example:
1)Qualification with components
(DegreeName, Year, UniversityName)
2)Address with component
(street, city, state postalcodes)
•Derived Attributes
Attribute value is dependent on some other attribute.
example: Age depends on DateOfBirth. 6
So24/11/10
age is a derived attribute. [Link] Nemade
•Single-valued
having only one value rather than a set of values.
Ex. PlaceOfBirth–single string value., Id of student
•Multi-valued
having a set of values rather than a single value
[Link] attribute for student
PreviousDegree attribute for student
Phone_numbers.
•Attributes can be:
simple single-valued, simple multi-valued,
composite single-valued or composite multi-valued
24/11/10
[Link] Nemade
Relationships
•When two or more entities are associated with each other,
we have an instance of a Relationship.
•E.g.: A person Ram worksfor company Mahindra
•Relationship worksfor has person and company as the
participating entities
.•Formally, worksfor person × Company
∩
•(p,c) Є worksfor person ‘p’ worksfor company ‘c’
•worksfor is called a relationship Type/Set.
Person_id company_id
person worksfor company
Person_name
Person_address 8
company_address
[Link] Nemadecompany_name
24/11/10
E-R diagram
Relationship Set
borrower
24/11/10
[Link] Nemade
An attribute can also be property of a relationship set.
For instance, the depositor relationship set between
entity sets customer and account may have the attribute
access-date
customer_id Account_id
customer Depositor account
customer_name
customer_address balance
company_name
Access_date
10
24/11/10
[Link] Nemade
11
24/11/10
[Link] Nemade
Degree of a Relationship Set
Degree:
the number of participating entities.
•Degree 2: binary :associate with two entities
publisher publishes book
•Degree 3: ternary: associate with three entities
teacher teaches subject
student
•Degree n: n-ary: associated with n entities 12
24/11/10
[Link] Nemade
Mapping Cardinalities
• 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:
One to one (1:1)
One to many(1:N)
Many to one(N:1)
Many to many (M:N)
13
24/11/10
[Link] Nemade
Cardinality Constraints
• We express cardinality constraints by drawing either a
directed line (), signifying “one,” or an undirected line
(—), signifying “many,” between the relationship set and
the entity set.
• E.g.: One-to-one relationship:
– A customer is associated with at most one loan via
the relationship borrower
– A loan is associated with at most one customer via
borrower
14
24/11/10
[Link] Nemade
One to one:
An entity in A is associated with at most one entity in B & an
entity in B is associated with at most one entity in A.
Ex. A customer with single account in given branch
customer Depositor account
15
24/11/10
[Link] Nemade
One to many:
An entity in A is associated with any number of entities (zero or
more) in B . An entity in B ,however, can be associated with at most
one entity in A.
Ex1. A customer having two accounts at a given
branch
customer Depositor account
[Link] the one-to-many relationship a loan is associated with at most
one customer via borrower, a customer is associated with several
(including 0) loans via borrower
16
24/11/10
[Link] Nemade
Many to one:
An entity in A is associated with at most one entity in B.
An entity in B ,however, can be associated with any number
(zero or more )of entities in A
Ex. Many employees works for company
Employee worksfor company
• In a many-to-one relationship a loan is associated with several
(including 0) customers via borrower, a customer is associated
with at most one loan via borrower
17
24/11/10
[Link] Nemade
Many to many:
An entity in A is associated with any number (zero or more) of
entities in B & an entity in B is associated with any number
(zero or more )of entities in A
Ex1. Employee works on number of projects & project can be
handled by number of employees
Employee worksfor project
Ex2.A customer is associated with several (possibly 0) loans via
borrower
A loan is associated with several (possibly 0) customers via borrower
18
24/11/10
[Link] Nemade
Participation Constraints:
•An entity set may participate in a relation either totally or
partially.
•Total participation:
Every entity in the set is involved in some association (or
tuple) of the relationship.
•Partial participation:
Not all entities in the set are involved in association (or
tuples) of the relationship
E1 R E2
19
24/11/10
total partial
[Link] Nemade
Example of total/partial Participation
EX1
name name
phone
N
Belongs 1
Professor Department
to
address
location
(many-to-one)
EX2
name name
phone
1
N
Professor guides student
address
rollno
(one-to-many) 20
24/11/10
[Link] Nemade
E-R Diagrams
Entity :- rectangle
Attribute: - ellipse connected to rectangle
Multi-valued attribute: - double ellipse
Composite attribute: - ellipse connected to ellipse
derived attribute:- dashed ellipse
Primary key:- underlined
Relationship:- Diamond
Mname
Ex1 Fname
Lname
Phone_numbers
studname
Rollno
student
AdmissionYear
sex
Emailaddress
21
Age
DOB
24/11/10
[Link] Nemade
Ex2
Ex3
22
24/11/10
[Link] Nemade
Relationship Sets with Attributes
23
24/11/10
[Link] Nemade
Roles
•Entity sets of a relationship need not be distinct
•The labels “manager” and “worker” are called roles; they
specify how employee entities interact via the works-for
relationship set.
•Roles are indicated in E-R diagrams by labeling the lines that
connect diamonds to rectangles.
•Role labels are optional, and are used to clarify semantics of
the relationship
24
24/11/10
[Link] Nemade
Keys
• Key:– an attribute or a collection of attributes whose value(s)
uniquely identify an entity in the entity set.
• A super key of an entity set is a set of one or more attributes
whose values uniquely determine each entity.
roll_no of student entity set.
• A candidate key of an entity set is a minimal super key
– Customer-id is candidate key of customer
– account-number is candidate key of account
• Although several candidate keys may exist, one of the
candidate keys is selected to be the primary key.
25
24/11/10
[Link] Nemade
•A Primary key is the key chosen by database designer as a
principal means of identifying entities in the entity set.
•An entity set which has a primary key is called as
strong entity set.
•The combination of primary keys of the participating entity
sets forms a super key of a relationship set.
(customer-id, account-number) is the super key of depositor
26
24/11/10
[Link] Nemade
Foreign Key:
An attribute or set of attributes ,within one relation that
matches the candidate key of some (possibly the same) relation.
For example, the inclusion of branch_no in Branch & Staff relation,
Links each Branch to the details of Staff working at that Branch.
In Branch relation branch_no is primary key. However, in the Staff
relation branch_no attribute exist to match Staff to branch office
they work in In staff relation ,branch_no is foreign key.
27
24/11/10
[Link] Nemade
Weak Entity Sets
Weak Entity Set: An entity set whose existence depends
upon some other entity in a strong entity set.
.An entity set that does not have a primary key is referred to
as a weak entity set.
•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.
•Each weak entity is associated with some entity of the owner
entity set through a special relationship
28
24/11/10
[Link] Nemade
We denote a weak entity set by double rectangles.
We underline the discriminator of a weak entity set with a
dashed line.
S R W
Always total
payment-number – discriminator of the payment entity set
Primary key for payment – (loan-number, payment-number) 29
24/11/10
[Link] Nemade
Representing Weak Entity Sets
A weak entity set becomes a table that includes a
column for the primary key of the identifying strong
entity set
30
24/11/10
[Link] Nemade
Partial key semester
sectionno
Course_id
year
Has section
course
section
professor
classtime
name
A popular course may have several sections each taught
by a different professor and having its own class room
and meeting times
Partial key: Uniquely identifies a section among the set
of sections of a particular course
31
24/11/10
[Link] Nemade
Extended E-R fetures
Specialization
• 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. 32
24/11/10
[Link] Nemade
Specialization Example
33
24/11/10
[Link] Nemade
Generalization
• 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.
34
24/11/10
[Link] Nemade
Specialization and Generalization (Contd.)
• Can have multiple specializations of an entity set based
on different features.
• E.g. permanent-employee vs. temporary-employee, in
addition to officer vs. secretary vs. teller
• Each particular employee would be
– a member of one of permanent-employee or
temporary-employee,
– and also a member of one of officer, secretary, or
teller
• The ISA relationship also referred to as superclass -
subclass relationship 35
24/11/10
[Link] Nemade
Design Constraints on a Generalization
• Constraint on which entities can be members of a
given lower-level entity set.
– condition-defined
• E.g. all customers over 65 years are members
of senior-citizen entity set; senior-citizen ISA
person.
– user-defined define by the user.
36
24/11/10
[Link] Nemade
Constraint on whether or not entities may
belong to more than one lower-level entity set
within a single generalization.
Disjoint
an entity can belong to only one lower-
level entity set
Noted in E-R diagram by writing disjoint
next to the ISA triangle
Specified by d in EER diagram
37
24/11/10
[Link] Nemade
38
24/11/10
[Link] Nemade
Overlapping
an entity can belong to more than one
lower-level entity set
39
24/11/10
[Link] Nemade
Design Constraints on a Specialization/Generalization
(Contd.)
• Completeness constraint -- specifies whether or not an
entity in the higher-level entity set must belong to at
least one of the lower-level entity sets within a
generalization.
– total : an entity must belong to one of the lower-
level entity sets
– partial: an entity need not belong to one of the
lower-level entity sets
40
24/11/10
[Link] Nemade
41
24/11/10
[Link] Nemade
Aggregation
One of the limitation of E-R model is that it can not express
relation ship among relationship.
Consider the ternary relationship works-on,
Suppose we want to record managers for tasks performed
by an employee at a branch
42
24/11/10
[Link] Nemade
Aggregation (Cont.)
Aggregation is an abstraction through which relationship
treated as higher level entities.
Thus the relationship set works_on relating entity set
employee, branch,job is consider as a higher level entity set
called works_on.
We can then create binary relationship manages between
works_on & manager to represent who manage what task.
43
24/11/10
[Link] Nemade
E-R Diagram With Aggregation
44
24/11/10
[Link] Nemade
Summary of Symbols Used in E-R Notation
45
24/11/10
[Link] Nemade
Summary of Symbols (Cont.)
46
24/11/10
[Link] Nemade
Alternative E-R Notations
47
24/11/10
[Link] Nemade
Reduction of an E-R Schema to Tables
• Primary keys allow entity sets and relationship
sets to be expressed uniformly as tables which
represent the contents of the database.
• A database which conforms to an E-R diagram can
be represented by a collection of tables.
• For each entity set and relationship set there is a
unique table which is assigned the name of the
corresponding entity set or relationship set.
• Each table has a number of columns (generally
corresponding to attributes), which have unique
names.
• Converting an E-R diagram to a table format is
the basis for deriving a relational database design 48
24/11/10
from an E-R diagram. [Link] Nemade
Representing Entity Sets as Tables
• A strong entity set reduces to a table with the same
attributes.
49
24/11/10
[Link] Nemade
Representing Weak Entity Sets
A weak entity set becomes a table that includes a
column for the primary key of the identifying strong
entity set
50
24/11/10
[Link] Nemade
Representing Relationship Sets as Tables
• A many-to-many relationship set is represented as a
table with columns for the primary keys of the two
participating entity sets, and any descriptive attributes
of the relationship set.
• E.g.: table for relationship set borrower
51
24/11/10
[Link] Nemade
Entity vs. Attribute
• Should address be an attribute of Employees or an entity
(connected to Employees by a relationship)?
• Depends upon the use we want to make of address
information, and the semantics of the data:
• If we have several addresses per employee, address
must be an entity (since attributes cannot be set-
valued).
• If the structure (city, street, etc.) is important, e.g., we
want to retrieve employees in a given city, address must
be modeled as an entity (since attribute values are
atomic).
52
24/11/10
[Link] Nemade