3 E R Diagram
3 E R Diagram
The term entity is widely used in database systems to mean any distinguishable object that
is to be presented in the database. Entity is a thing that exists and is distinguishable. A
group of all similar entities forms an entity. In general these will be associations or
relationships linking the basic entities together.
Suppliers Projects
Locations Departments
In the above figure relationships are all bidirectional that is, they may all be traversed in
either direction. So two queries can be answered by this :
a) Given an employee, find the corresponding departments
b) Given a department, find all corresponding employees
Though entities and relationships are two dissimilar types of objects, an association
between entities may itself be considered as an entity .
“Supplier S2 supplies part P4 to project J3” tells us more than the combination “Supplier
S2 supplies part P4” and “Part P4 is used in Project J3. We can’t deduce the first of these
three association knowing only the 2nd & 3rd.
n m
Cardinality Weak Entity
Strong Weak Relationship
The overall logical structure of a database can be expressed graphically by a E-R diagram.
Example
The set of all persons having an account at a bank can be defined as the entity set
customer. Similarly the entity set account might represent the set of all accounts in a
particular branch of a particular bank.
Mapping Constraints
One important constraint is mapping cardinalities which express the number of entities to
which another entity can be associated via a relationship.
One -to-one :
One-to-one relationship
In the above figure there is a relationship Head-of connects two entities Teacher and Dept.
If we assume that each department can have only one head and one teacher cannot be the
head of more than one department.
One-to-many
One-to-many relationship
In the above example if we assume that each course is taught by one teacher only then the
relationship is one to many between Teacher & Course. Similarly the same relationship is
many-to-one from Course & Teacher.
Many-to-many relationship
Many-to-many relationship
In this example one employee may work in several projects and one project may have
several employees.
Key
A super key for an entity set is a set of one or more attributes whose value uniquely
identifies the entities in the entity set. For a student {roll-no, name, address} can be
considered to be a superkey. A candidate key is a minimal superkey. A primary key is
a candidate key that is chosen by the database designer.
More Examples
Pub-by
Publisher
grade
study
Student Course
assist
Multiple relationships
Course pre-req
min-grade
Self-relationship
Branch
Ternary relationship
Weak entity
Although each transaction entity is distinct, transaction on different accounts may share
the same tr-no. Here the key is {ac-no, tr-no}
name addr
Suppliers
Furnish
price
Quotations
proposed-delv-date
Of
Items
ISA ISA
isa Employee
Manager Work-in
i-no btch-no
Look
After Depts Sale Item
d-no d-name
Supplied
By
Supplier
s-name s-address
student
study Teacher
grade
Course Emp-bys
d-name tel-no
Converting E-R diagrams into Relations
Consider the figure below showing two entities and one relationship :
Course Pre-req
m
crs-no min-grade
COURSE (crs-no, crs-title, credit)
Key : crs-no
EER model provides generalization and specialization (both are ISA type
relationships), creating class/subclass hierarchies