ER Diagram
ER Diagram
(ERD)
ER Model/Diagram
a data modeling technique that graphically illustrates an information
system’s entities and the relationships between those entities.
a conceptual and representational model of data used to represent the entity
framework infrastructure.
used as a high-level logical data model, which is useful in developing a
conceptual design for databases.
An ER Model maps well to the relational model. i.e. the constructs used in
ER Model can be easily transferred into relational table.
An ER Model can be used by the database designer to communicate the
database design to the user.
An ER Model can be used as a design plan by the database developer to
implement a data model in specific DBMS software like Oracle, Ms SQL .
Entity-Relationship (E-R) Model
Entities
An entity is a “thing” or “object” in the real world that is
distinguishable from other objects.
Entity can have anything that has an independent existence
and about which we collect data.
Entity-Relationship (E-R) Model
E.g.
In a school database, the students, teachers, classes, courses, or
projects can be taken as an entity.
Entities are represented by means of rectangle
Entity set
Entity-Relationship (E-R) Model
E.g.: the entity set Employee (all employees of a bank) and the
entity set Customer( all customer of a bank ) may have members
in common.
Attributes
An entity is represented by a set of attributes.
Attributes are used to describe the property of an entity.
E.g.: a student entity may have Roll_no, Name, DOB, Age,
Address , Mobile_no as attribute.
For each attribute there is a set of permitted values called
domain(or range) of that attribute.
Entity-Relationship (E-R) Model
E.g.: a student’s name cannot be numeric value, it has to be
alphabetic. A student’s age cannot be negative value etc. A
student’s roll no. can be numeric between some range(0-10000).
Attributes are represented by ellipse.
Attribute
Student
relationship
Entity-Relationship (E-R) Model
Relationships
Student
Enrolls Course
Entity-Relationship (E-R) Model
Relationship set
A set of relationships of similar types is called relationship set.
The following relationship set Enrolls (E1, E2, E3) depicts;
S1 E1 C1
S2 E2 C2
S3 E3 C3
Account
customer depositor
Types of Attributes
Moble_no DoB
student
a DOB is an atomic
Value of day-month-year.
Roll_no
Types of Attributes
Moble_no DoB
student
name
Roll_no
L_name
F_name
Types of Attributes
Moble_no DoB
student
name
Roll_no
L_name
F_name
Types of Attributes
Moble_no DoB
student
name
phone_no Roll_no
L_name
F_name
Types of Attributes
Dashed ellipse.
Age
(dashed ellipse)
Moble_no DoB
student
name
phone_no Roll_no
L_name
F_name
Types of Attributes
Roll_no Roll_no
-------------
Customer-id Customer-city
branch-city
job
employee-name stree branch- assets
t name
employee- city
id
Set A Set B
E1 W1 D1
E2 W2 D2
E3 W3 D3
E-R Diagram
1 Works_at 1 Department
Employee
One entity from entity set A can be associated with more than
one entities of entity set B however an entity from entity set B,
can be associated with at most one entity of entity set A.
Set A Set B
A1 B1 1 Give
M Order
B2 Customer
A2 B3
B4
A3 B5
E-R Diagram
ID(PK) Name City O_no(P.K) Item_Name Cost
Date
Customer
1 Give
M Order
C2 O5 O4 Bucket 700
C3 O4 O5 Stove 1300
One-to-Many(1-M) Relationship
Customer
1 Give
M Order
More than one entities from entity set A can be associated with
at most one entity of entity set B, however an entity from entity
set B can be associated with more than one entity from entity
set A.
E.g.: many students can study in a single college but a student
cannot study in many colleges at the same time.
set A Set B
S1 C1
S2 C2 student M Study
1 college
S3 C3
S4 C4
Many-to-One(M-1) Relationship
E-R diagram
Sid(PK) Name Age Cid(P.K) Program Duration
Date
M 1
student study College
One entity from A can be associated with more than one entity
from B and vice versa.
Set A Set B
S1 C1 student M Study
N Course
S2 C2
S3 C3
S4 C4
S5 C5
Name Cname
E-R Diagram
M N
student Study Course
RollNo(PK)
Age Cid(PK) Chour
1 1
1 M
Customer Borrower Loan
M 1
Customer Borrower Loan
M N
Customer Borrower Loan
Participation Constraints
Partial Total
Customer Borrower Loan
Participation Participation
Partial Participation exists when all the entity of an entity type is
not associated with one or the other entity of another entity
type
E.g. we have two entity type ‘Customer’ and ‘Order’. Then there
can be ‘Customer’ who have not done any order. So, here there
is partial participation of the entity in the relationship.
Partial 1 Total N
Customer Makes Order
Participation Participaton
Participation Constraints
1 M
Employee Has Dependent
Partial Total
Participation Participation
Weak Entity Type
Weak entity type doesn't have a key attribute. Weak entity type
can't be identified on its own. It depends upon some other
strong entity for its distinct identity. This can be understood with
a real-life example. There can be children only if the parent exits.
There can be no independent existence of children. There can be
a room only if building exits. There can be no independent
existence of a room. A weak entity is represented by a double
outlined rectangle. The relationship between a weak entity type
and strong entity type is called an identifying relationship and
shown with a double outlined diamond instead of a single
outlined diamond. This representation can be seen in the
diagram below.
Example: If we have two tables of Customer(C_id, Name,
Mobile, Age, Gender) and Address(Locality, Town, State).
Here we cannot identify the address uniquely as there can
be many customers from the same locality. So, for this, we
need an attribute of Strong Entity Type i.e ‘Customer’ here
to uniquely identify entities of 'Address' Entity Type.
Entity, Entity Type, and Entity Set
Town Locality
C_id(PK)
Age
Mobile
Name
State
Gender
1 Rela M
Professor Dependent
tede
Name Relation
DOB
ID(PK)
Q. Construct an E-R Diagram for Hospital Management System.
Convert this diagram into Relation Schema
Prec_id
Doc_id Doctor
Problem Date of
Examination
Q. Construct an E-R Diagram for Hospital Management System.
Convert this diagram into Relation Schema
Problem Date of
Examination
Relation Schema of Hospital Management System
Schemas
Patient(P_id(PK), Pname, P_mobile, P_addr, H-id(FK))
MedicalRecord(Prec_id(PK), DateofExamination, Problem,
P_id(FK))
Doctor(D_id(PK), Dname, Salary, Qualification, H_id(FK))
Hospital( H_id(PK), Hname, Haddr, Hcity)
Q. Construct an E-R Diagram for Library Management System.
Showing the proper relationship Book, Publishers, Member and
Librarian. Convert this diagram into Relation Schema
Step 1: Identify the Entities.
Authentication System
Q. Construct an E-R Diagram for Library Management System.
Showing the proper relationship Book, Publishers, Member and
Librarian. Convert this diagram into Relation Schema
Pub_id Publishers
Price Title
Q. Construct an E-R Diagram for Library Management System. Showing the proper
relationship Book, Publishers, Member and Librarian. Convert this diagram into
Relation Schema
Step 3: Identify the Relationship an participation Constraints
Password name
Login_id L_id
Authorization 1 Login
M
Librarian
System
1 M Mobile
Book_id
Paddr Author
Maintain
Issue
Book M
Title
M N
Price
Mobile name
Published Member
by
N
Mem_Id
Address
Pub_id Publishers
Address
name
Relation Schema of Library Management System
Schemas
Authorization System( Login_id(PK), Password)
Librarian( L-id(PK), name, mobile, Login_id(FK))
Book( book_id(PK), Title, Author, Price, L_id(FK), Mem_id(FK))
Members( Mem_id(PK), name, address, mobile)
Published by( book_id(FK), Pub_id(FK)
Publishers( Pub_id ( PK) , Address, Name)
Issue(L_id(FK), Mem_id(FK))
Q. Construct an E-R Diagram for Banking System. Convert this
diagram into Relation Schema
Employee
Q. Construct an E-R Diagram for Banking System. Convert this
diagram into Relation Schema
c_id balance
A_no
C_name
L_no
Account
Customer
Amount
B_name B_code
E_id Employee
Branch E_Addr
E_name
B_city
Q. Construct an E-R Diagram for Banking System. Convert this
diagram into Relation Schema
Deposit or
Customer Account
1 Withdraw 1
1 Mobile M
A_type
has
borrows
B_name
1
M
M 1 Branch
Provides
Loan 1
Amount
E_Addr
E_name
Relation Schema of Banking System
Schemas
Customer( C_id(PK) , C_name, mobile, A_no(FK))
Loan ( L_no(PK), Amount, L_type, C_id(FK), B_code(FK))
Account ( A_no(PK), balance, A_type, B_code(FK))
Works( E_id(PK), E_name, E_addr, B_code(FK))
Branch( B_code(PK), B_city, B_name)
Conversion from ER diagram to
relational Model
Rule 1: Entity type becomes a table
Rule 2: All single-valued attribute becomes a
column for the table
Rule 3: A key attribute of the entity type
represented by the primary key.
Rule 4: The multivalued attribute is represented
by a separate table
Rule 5: Composite attribute represented by
components
Rule 6: Derived attributes are not considered in
the table
Example 2: With composite attribute
The entity set will be the table and the simple attributes
of the composite attributes will become the attributes of
the table while the composite attribute itself will be
ignored during conversion.