Outline: Looping
Outline: Looping
Looping
• Basic concept of E-R diagram
• Types of Attributes
• Mapping Cardinality
• Weak Entity Sets
• Extended E-R features
• Generalization and Specialization
• Constraints on Specialization and
Generalization
• Aggregation
• E-R diagram of Hospital Management System
• Reduction to E-R Database Schema
• Database Models
• Integrity Constraints
Basic concept of E-R diagram
Section - 1
Basic concepts
What is Database Design?
Database Design is a collection of processes that facilitate the designing, development, implementation
and maintenance of enterprise database management systems.
What is E-R diagram?
E-R diagram: (Entity-Relationship diagram)
It is graphical (pictorial) representation of database.
It uses different types of symbols to represent different objects of database.
Entity
An entity is a person, a place or an object.
Entity Name
An entity is represented by a rectangle which contains the name of an entity.
Entities of a college database are: Symbol
Student
Professor/Faculty
Course
Department
Student Faculty Course
Result
Class
Subject
Relationship
Name
Symbol
Each and every entity must have one primary key attribute.
Relationship between 2 entities is called binary relationship.
Ternary Relationship
ProjectID Project Name
Project
Middle name
Types of Attributes
Roll No Phone No
Types of Attributes
Middle
Name
First Name Last
Single Name
Simple
Value
RollNo Name Composite Apartment
Derived Composite
Multiple Stored
Value
Phone No Birth Date Area
Exercise
Draw an E-R diagram of Banking Management System.
Draw an E-R diagram of Hospital Management System.
Draw an E-R diagram of College Management System.
Take only 2 entities
Keep proper relationship between two entities
Use all types of attributes
Descriptive Attribute
Attributes of the relationship is called descriptive attribute.
Descriptive
Attribute
Issue
RollNo Name Date BookNo Name
EmpID Name
Coordinator
Reports_T
Faculty
o
Head
Branch Experience
Recursive Relationship Set
The same entity participates in a relationship set more than once then it is called recursive
relationship set.
FacID FName DeptID DName
Post Recursive
Relationship
FName Post Set DName
Ajay Professor Prof. Computer
f.
Haresh Professor PPrroof./ Civil
HOD
Rames Mechanica
HOD
h l
Mapping Cardinality
Section - 3
Mapping Cardinality (Cardinality Constraints)
It represents the number of entities of another entity set which are connected to an entity
using a relationship set.
It is 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
One to Many
Many to One
Many to Many
One-to-One relationship (1 – 1)
An entity in A is associated with only one entity in B and an entity in B is associated with
only one entity in A.
Example: A customer is connected with only one loan using the relationship borrower and a
loan is connected with only one customer using borrower.
One-to-Many relationship (1 – N)
An entity in A is associated with more than one entities in B and an entity in B is
associated with only one entity in A.
Example: A loan is connected with only one customer using borrower and a customer is
connected with more than one loans using borrower.
Many-to-One relationship (N – 1)
An entity in A is associated with only one entity in B and an entity in B is associated with
more than one entities in A.
Example: A loan is connected with more than one customer using borrower and a
customer is connected with only one loan using borrower.
Many-to-Many relationship (N – N)
An entity in A is associated with more than one entities in B and an entity in B is
associated with more than one entities in A.
Example: A customer is connected with more than one loan using borrower and a loan is
connected with more than one customer using borrower.
Mapping Cardinality (Cardinality Constraints) [Exercise]
Draw an E-R diagram and specify which type of mapping cardinality will be there in the
following examples:
Each customer has only one account in the bank and each account is held by only one customer. [single
account]
Each customer has only one account in the bank but an account can be held by more than one customer.
[joint account]
A customer may have more than one account in the bank but each account is held by only one customer.
[multiple accounts]
A customer may have more than one account in the bank and each account is held by more than one
customer. [join account as well as multiple accounts]
A student can work in more than one project and a project can be done by more than one student.
A student can issue more than one book but a book is issued to only one student.
A subject is taught by more than one faculty and a faculty can teach more than one subject.
Participation Constraints
Section - 4
Participation Constraints
It specifies the participation of an entity set in a relationship set.
There are two types participation constraints
Total participation
Partial participation
Payment-date
Saving_Account Current_Account
Sub Class
Generalization v/s
Specialization
Section - 7
Generalization v/s Specialization
Generalization Specialization
It splits an entity to form multiple new
It extracts the common features of multiple
entities that inherit some feature of the
entities to form a new entity.
splitting entity.
Name Address Name Address
Salar
SPI
Person Person y
Name Name
IS IS
Top-down approach
Address A Address A
Bottom-up
approach
Salar Salar
SPI SPI
y y
Generalization v/s Specialization
Generalization Specialization
The process of creation of group from The process of creation of sub-groups within
various entities is called generalization. an entity is called specialization.
It is Bottom-up approach. It is Top-down approach.
The process of taking the union of two or The process of taking a sub set of higher level
more lower level entity sets to produce a entity set to form a lower level entity set.
higher level entity set.
It starts from the number of entity sets and It starts from a single entity set and creates
creates high level entity set using some different low level entity sets using some
common features. different features.
Generalization & Specialization example
Name Address
PID City
Person
IS
A
Salar Balanc
Employee Customer
y e
IS
A
Days
Hour Worked
Worked
Exercise
Give the examples of Generalization/Specialization in the following E-R diagram:
Hospital Management System.
College Management System.
Bank Management System.
Insurance Company.
Constraints on
Specialization and
Generalization
Section - 8
Constraints on Specialization and Generalization
Constraints
Disjoint Participation
Disjoin
t
Batsman Bowler ISA
(Sub class) (Sub class)
Full-time Part-time
(Sub class) (Sub class)
All the players are associated with only one sub class either (Batsman or
Bowler).
Non-disjoint (Overlapping) Constraint
It specifies that an entity of a super class can belong to more than one lower-level entity
set (sub class).
Specified by ‘o’ or by writing overlapping near to the ISA triangle.
Employee
Cricketer (Super class)
(Super class)
disjoint
Non-
Batsman Bowler ISA
(Sub class) (Sub class)
Faculty Head
(Sub class) (Sub class)
One player (Yuvraj singh) is associated with more than one sub
class.
Constraints on Specialization and Generalization
Constraints
Disjoint Participation
Professor Head
(Sub class) (Sub class)
All the players are associated with minimum one sub class either (Batsman or
Bowler).
Partial (Optional) Participation
Partial participation specifies that every entity in the super class does not belong to any of
the subclass of specialization.
Specified by a single line in E-R diagram.
Employee
Cricketer (Super class)
(Super class)
Professor Head
(Sub class) (Sub class)
Aggregation in E-R diagram
Section - 9
Limitation of E-R diagram
In E-R model we cannot express relationships between two relationships.
Customer
Company
Borrow Borrow
Loan Loan
MRID
PatID Name HosID Name
Indoor Outdoor
Doctor
RoomNo
IPDID OPDID DrID Dr Name
Charge
Reduce the E-R diagram
to Database Schema
Section - 11
Reduce the E-R diagram to database schema
PhoneNo (T2)
Reduce the E-R diagram to database schema
WifeID WName
Step 3: Reduce 1:1 Mapping Cardinality:
Convert both entities in to table with proper Wife
attribute.
Place the primary key of any one table in to the Having
another table as a foreign key.
Place the primary key of the Wife table WifeID in the Person
Disjoint
E R E ISA ISA
One to One Total Disjoint
Specialization/ Specialization/
E R E Generalization Generalization
One to Many
E R E Overlapping
Hierarchical Model
Network Model
Entity-relationship Model
Relational Model
Student Professor
The hierarchy starts from the Root data, and expands like a tree, adding child nodes to
the parent nodes.
In hierarchical model, data is organized into tree-like structure with one-to-many
relationship between two different types of data, for example, one department can have
many professors and many students.
Network Model
This is an extension of the hierarchical model, allowing many-to-many relationships in a
tree-like structure that allows multiple parents.
B C
D E F
Entity-relationship Model
In this database model, relationships are created by dividing object of interest into entity
and its characteristics into attributes.
Attributes
RollNo Name BookNo Name
Relationship