Unit 2
Unit 2
(DBMS)
GTU # 3130703
Unit-2
Data Models
Looping
Outline
• 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
An entity is represented by a rectangle which contains the name
Name of an
entity.
Symbo
Entities of a college database are: l
Student
Professor/Faculty
Course
Student Faculty Course
Department
Result
Class
Subject
Exerci Write down the different entities of
se bank database.
Exerci Write down the different entities of
se hospital database.
Entity Set
It is a set (group) of entities of same type.
Examples:
All persons having an account in a bank
All the students studying in a college
All the professors working in a college
Set of all accounts in a bank
Attributes
Attribute is properties or details about an entity. Attribute
Name
An attribute is represented by an oval containing name of an attribute.
Attributes of Student are: Symbo
Roll No l
Student Name
RollNo Name
Branch
Semester
Address
Mobile No Student
Age
SPI
Backlogs
Symbo
l
Project
Technolo
Branch Branch Sem
gy
Middle
First Name
Last
Single Name Name
Simple
Value
Composit Apartme
RollNo Name e nt
Composit
Derived
e
Multiple Stored
Value Phone Birth
Date Area
No
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.
Descripti
ve
Attribute
Issue
BookN
RollNo Name Date Name
o
Coordinat
Reports_
Faculty or
To
Hea
d
Experien
Branch
ce
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
Work
Faculty Department
s
Recursive
Post Relations
hip
FNam DName
Post Set
e
Prof. Compute
Profess of.
Ajay PPrrof./ r
or
HOD Civil
Hares Profess
h or Mechanic
al
Rames
HOD
h
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.
Weak
Strong Entity Weak
Entity Set Relationsh Entity Set
ip
Disjoin
t
E R E ISA ISA
One to Total Disjoint
One Specializatio Specializatio
E R E n/ n/
Generalizati Generalizati
One to on on
Many
E R E Overlappi
ng
Many to ISA ISA
One
Partial Overlapping
E R E
Specializatio Specializatio
Many to n/ n/
Many Generalizati Generalizati
on on
Integrity
COnstraints
Integrity COnstraints
□Check
□ This constraint defines a business rule on a column. All the rows in that column must satisfy
this rule.
□ Limits the data values of variables to a specific set, range, or list of values.
□ The constraint can be applied for a single column or a group of columns.
□ E.g. value of SPI should be between 0 to 10.
□Not null
□ This constraint ensures all rows in the table contain a definite value for the column which is
specified as not null. Which means a null value is not allowed.
□ E.g. name column should have some value.
□Unique
□ This constraint ensures that a column or a group of columns in each row have a distinct
(unique) value.
□ A column(s) can have a null value but the values cannot be duplicated.
□ E.g. enrollmentno column should have unique value.
Integrity COnstraints
□Primary key
□ This constraint defines a column or combination of columns which uniquely identifies each row
in the table.
□ Primary key = Unique fiey + Not null
□ E.g. enrollmentno column should have unique value as well as can’t be null.
□Foreign key (referential integrity constraint)
□ A referential integrity constraint (foreign key) is specified between two tables.
□ In the referential integrity constraints, if a foreign key column in table 1 refers to the
primary key column of table 2, then every value of the foreign key column in table 1 must
be null or be available in primary key column of table 2.
Foreign Key
RollN Student_Na DeptI
DeptID Dept_Name HOD o me D
1 Comput Dosh
101 Raj Patel 1
er i
2 I Vyas
102 Meet Shah 2
T h
Superclass v/s Subclass
Section - 6
Superclass v/s Subclass
Super Class Sub Class
A superclass is an entity from which A subclass is an entity that is
another entities can be derived. derived from another entity.
E.g, E.g,
an entity account has two subsets saving_account and current_account
saving_account and current_account entities are derived from entity
So an account is superclass. account.
So saving_account and
current_account are subclass.
Account Super
Class
Saving_Accou Current_Acco
nt unt
Sub Class
Generalization v/s
Specialization
Section - 7
Generalization v/s Specialization
Generalization Specialization
It splits an entity to form
It extracts the common features
multiple new entities that inherit
of multiple entities to form a new
Addres some feature of theAddres
splitting
entity. Nam Nam
e s entity. e s
Sala
SPI
Person Person ry
Nam Nam
e e IS
Addre IS
A Addres A
ss s
Top-down
approach
Bottom-up
approach
Sala Sala
SPI SPI
ry ry
Generalization v/s Specialization
Generalization Specialization
The process of creation of group The process of creation of sub-
from various entities is called groups within an entity is called
generalization.
It is Bottom-up approach. specialization.
It is Top-down approach.
The process of taking the union of The process of taking a sub set of
two or more lower level entity higher level entity set to form a
sets to produce a higher level entity lower level entity set.
set.
It starts from the number of entity It starts from a single entity set and
sets and creates high level entity set creates different low level entity sets
using some common features. using some different features.
Generalization & Specialization example
Nam Addres
e s
PID City
Person
IS
A
Salar Balan
Employee Customer
y ce
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
Constraint
s
Participati
Disjoint
on
Non-
Total
disjoint Partial
Disjoint (Mandator
(Overlappin (Optional)
y)
g)
Disjoint Constraint
It describes relationship between members of the superclass and
subclass and indicates whether member of a superclass can be a
member of one, or more than one subclass.
Types of disjoint constraints
Disjoint Constraint
Non-disjoint (Overlapping) Constraint
Disjoint Constraint
It specifies that the entity of a super class can belong to only one
lower-level entity set (sub class).
Specified by ‘d’ or by writing disjoint near to the ISA triangle.
Employee
Cricketer (Super class)
(Super
class)
Disjoi
nt
Batsman Bowler
(Sub (Sub ISA
class) 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
(Sub (Sub ISA
class) class)
Faculty Head
(Sub class) (Sub class)
Constraint
s
Participati
Disjoint
on
Non-
Total
disjoint Partial
Disjoint (Mandator
(Overlappin (Optional)
y)
g)
Participation (Completeness) Constraint
It determines whether every member of super class must
participate as a member of subclass or not.
Types of participation (Completeness) Constraint
Total (Mandatory) participation
Partial (Optional) participation
Total (Mandatory) Participation
Total participation specifies that every entity in the superclass must
be a member of some subclass in the specialization.
Specified by a double line in E-R diagram.
Employee
Cricketer (Super class)
(Super
class)
Batsman Bowler
(Sub (Sub ISA
class) class)
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)
Batsman Not associated Bowler
(Sub with any sub (Sub ISA
class) class
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.
Relation Relation
Relation
1 2
Custom
Company
er
Work
Employee Department
s
Customer
Can not connect two
relationship
Borro
Borrow
w
Loan Loan
MRID
PatID Name HosID Name
Medical Admitt
Has Patient Hospital
Record ed
Report
IS Tre Has
Name at s
A
Indoo Outdo
r or Doctor
RoomN
o
IPDID OPDID Dr
DrID
Char Name
ge
Reduce the E-R
diagram
to Database Schema
Section - 11
Reduce the E-R diagram to database schema
Cardinality:
Convert both entities in to table with House
proper attribute.
Place the primary key of table having 1 Having
mapping in to the another table having
many cardinality as a Foreign key. Person
Place the primary key of the Person table
PersonI
PersonID in the table House as Foreign key. D
PName
Disjoint
E R E ISA ISA
One to Total Disjoint
One Specializati Specializati
E R E on/ on/
Generalizat Generalizat
One to ion ion
Many
E R E Overlappi
ng
Many to ISA ISA
One
Partial Overlappin
E R E
Specializati g
Many to on/ Specializati
Many Generalizat on/
ion Generalizat
ion
Data Models
Section - 12
What is a Database Models?
A database model is a type of data model that defines the logical
structure of a database.
It determine how data can be stored, accessed and updated in a
database management system.
The most popular example of a database model is the relational model,
which uses a table-based format.
Type of Database Models
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.
Attribut
es
RollNo Name Relationsh BookN
Name
o
ip