0% found this document useful (0 votes)
20 views

DBMS Unit 1 - ER Models

Uploaded by

Karansingh Bisht
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

DBMS Unit 1 - ER Models

Uploaded by

Karansingh Bisht
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
You are on page 1/ 63

Data Models

 Looping
Outline
• Basic concept of E-R diagram
• Types of Attributes
• Mapping Cardinality
• Weak Entity Sets
• Generalization and Specialization
• Constraints on Specialization and
Generalization
• Aggregation
• E-R diagram of Hospital Management
System
• Reduction to E-R Database Schema
• Integrity Constraints
Basic concept of E-R
diagram
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.

4
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

5
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

6
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

7
Relationship
 Relationship is an association (connection) between several entities.
 It should be placed between two entities and a line connecting it to an
entity.
 A relationship is represented by a diamond containing relationship's
name.
Relationshi
p Name

Symbo
l

Student Issue Book

8
E-R Diagram of a Library System
Primary Primary
Key Attribut Key
es
RollNo Name Relationsh BookN
Name
o
ip

Student Issue Book

Branch Sem Entities Author Price

Each and every entity must have one primary


key attribute.
Relationship between 2 entities is called binary
relationship.

9
Ternary Relationship
ProjectI Project
D Name

Project

FacID Name RollNo Name

Faculty Guide Student

Technolo
Branch Branch Sem
gy

Relationship between 3 entities is called ternary


relationship.
10
Exercise
 Draw an E-R diagram of following pair of entities
 Customer & Account
 Customer & Loan
 Doctor & Patient
 Student & Project
 Student & Teacher
 Note: Take four attributes per entity with one primary key attribute.
Keep proper relationship between two entities.

11
Types of Attributes
Types of Attributes

Simple Attribute Composite Attribute


Cannot be divided into subparts Can be divided into subparts
E.g. RollNo, CPI E.g. Name
(first name, middle name,
last name)
Address
Symbol Symbol (street, road, city)
Name
First Last
Roll No name name
Middle
name

13
Types of Attributes

Single-valued Attribute Multi-valued Attribute


Has multiple (more than one)
Has single value
value
E.g. RollNo, CPI E.g. PhoneNo
(person may have multiple
phone nos)
EmailID
Symbol Symbol (person may have multiple
emails)
Roll No Phone
No

14
Types of Attributes

Stored Attribute Derived Attribute


It’s value is stored manually in It’s value is derived or calculated
database from other attributes
E.g. Birthdate E.g. Age
(can be calculated using
current date and birthdate)
Symbol Symbol
Birthdat
Age
e

15
Entity with all types of Attributes

Middle
First Name
Last
Single Name Name
Simple
Value
Composit Apartme
RollNo Name e nt
Composit
Derived
e

Age Student Address Street

Multiple Stored
Value Phone Birth
Date Area
No

16
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

17
Descriptive Attribute
 Attributes of the relationship is called descriptive attribute.

Descripti
ve
Attribute

Issue
BookN Name
RollNo Name Date
o

Student Issue Book

Branch Sem Author Price

18
Role
 Roles are indicated by labeling the lines that connect diamonds
(relationship) to rectangles (entity).
 The labels “Coordinator” and “Head” are called roles; they specify Faculty
entities interact with whom via Reports_To relationship set.
 Role labels are optional, and are used to clarify semantics (meaning) of
the relationship.
EmpID Name

Coordinat
Reports_
Faculty or
To
Hea
d
Experien
Branch
ce

19
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 Relationsh
ip
FNam DName
Post Set
e
Prof. Compute
Profess of.
Ajay PPrrof./ r
or
H OD Civil
Hares Profess
h or Mechanic
al
Rames
HOD
h 20
Mapping Cardinality
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

22
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.

customer borrow loan


A1 B1
C L
1 1
A2 B2 C L
2 2
C L
A B 3 3

 Example: A customer is connected with only one loan using the


relationship borrower and a loan is connected with only one customer
using borrower.

23
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.

customer borrow loan


A1 B1
C L
1 1
A2 B2 C L
2 2
C L
A B 3 3
L
4

 Example: A loan is connected with only one customer using borrower


and a customer is connected with more than one loans using
borrower.
24
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.

customer borrow loan


A1 B1
C L
1 1
A2 B2 C L
2 2
C L
A B 3 3
C
4

 Example: A loan is connected with more than one customer using


borrower and a customer is connected with only one loan using
borrower.
25
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.

customer borrow loan


A1 B1
C L
1 1
A2 B2 C L
2 2
C L
A B 3 3
C L
4 4

 Example: A customer is connected with more than one loan using


borrower and a loan is connected with more than one customer
using borrower.
26
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.

27
Weak Entity Set
Weak Entity Set
 An entity set that does not have a primary key is called weak entity
set.
Payment-
date
loan- amoun payment- Payment-
no t no amount

loan L_P payment

Weak
Strong Entity Weak
Entity Set Relationsh Entity Set
ip

• Weak entity set is indicated by double


rectangle.
• Weak entity relationship set is indicated by
double diamond.
29
Weak Entity Set
 The existence of a weak entity set depends on the existence of a
strong entity set.
 The discriminator (partial key) of a weak entity set is the set of
attributes that distinguishes all the entities of a weak entity set.
 The primary key of a weak entity set is created by combining the
primary key of the strong entity set on which the weak entity set is
existence dependent and the weak entity set’s discriminator.
 We underline the discriminator attribute of a weak entity set with a
dashed line.
 Payment entity has payment-no which is discriminator.
 Loan entity has loan-no as primary key.
 So primary key for payment is (loan-no, payment-no).

30
Superclass v/s Subclass
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
32
Generalization v/s
Specialization
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
Bottom-up
approach

Student Faculty Student Faculty

Top-down
approach
Sala Sala
SPI SPI
ry ry

34
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.

35
Generalization & Specialization example
Nam Addres
e s
PID City
Person

IS
A

Sala Balan
Employee Customer
ry ce
IS
A

Full Time Part Time

Days Hour
Worked Worked

36
Constraints on
Specialization and
Generalization
Constraints on Specialization and
Generalization

Constraint
s

Participati
Disjoint
on

Non-
Total
disjoint Partial
Disjoint (Mandator
(Overlappin (Optional)
y)
g)

38
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

39
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).
40
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)

One player (Yuvraj singh) is associated with more than


one sub class.
41
Constraints on Specialization and
Generalization

Constraint
s

Participati
Disjoint
on

Non-
Total
disjoint Partial
Disjoint (Mandator
(Overlappin (Optional)
y)
g)

42
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

43
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).
44
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)

45
Aggregation in E-R
diagram
Limitation of E-R diagram
 In E-R model we cannot express relationships between two
relationships.
Relation Relation
Relation
1 2

Entity 1 Relation Entity 2

47
Limitation of E-R diagram

Custom
Company
er

Work
Employee Department
s
Customer
Can not connect two
relationship
Borro
Borrow
w

Loan Loan

Process of creating an entity by combining various


components of E-R diagram is called aggregation.

48
E-R diagram of
Hospital Management
System
E-R diagram of Hospital Management System

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

50
Reduce the E-R
diagram
to Database Schema
Reduce the E-R diagram to database schema

Step 1: Reduce Entities and Simple


Attributes: PersonI
 An entity of an ER diagram is turned into Name
D
a table.
 Each attribute (except multi-valued Person
attribute) turns into a column (attribute)
in the table. Addres
City
s
 Table name can be same as entity
PhoneN
name. o
 Key attribute of the entity is the primary
key of the table which is usually Person (PersonID, Name,
underlined. Address, City)
 It is highly recommended that every table
should start with its primary key attribute
conventionally named as TablenameID.
52
Reduce the E-R diagram to database schema

Step 2: Reduce Multi-valued PersonI


D
PhoneN
o
Attributes:
 Multi-value attribute is turned into a
Person
new table.
 Add the primary key column into multi- PhoneNo (PhoneID, PersonID,
value attribute’s table. PhoneNo)

 Add the primary key column of the


Foreign Person (T1)
parent entity’s table as a foreign key Key
within the new (multi-value attribute’s)
table. Having
 Then make a 1:N relationship between
the Person table and PhoneNo table. PhoneNo (T2)

53
Reduce the E-R diagram to database schema
WifeID WName
Step 3: Reduce 1:1 Mapping
Cardinality:
 Convert both entities in to table with Wife
proper attribute.
 Place the primary key of any one table Having
in to the another table as a foreign key.
 Place the primary key of the Wife table Person

WifeID in the table Persons as Foreign key.


PersonI
PName
OR D
 Place the primary key of the Person table Person (PersonID, PName)
PersonID in the table Wife as Foreign key. Wife (WifeID, Wname, PersonID)
Wife (WifeID, Wname)
Person (PersonID, Pname,
WifeID)

54
Reduce the E-R diagram to database schema
HouseI
HName
Step 4: Reduce 1:N Mapping D

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

Person (PersonID, PName)


House (HouseID, Hname,
PersonID)

55
Reduce the E-R diagram to database schema
ActNo Balance
Step 5: Reduce N:N Mapping
Cardinality:
 Convert both entities in to table with Account
proper attribute.
Has_Ac
 Create a separate table for ct
relationship.
 Place the primary key of both entities Customer

table into the relationship’s table as


foreign key. CID CName
 Place the primary key of the Customer Customer (CID, CName)
table CID and Account table Ano in the Account (ActNo, Balance)
table Has_Acct as Foreign key. Has_Acct (HasAcctID, CID,
ActNo)

56
Summery of Symbols used in E-R diagram

Customer Name Hold


Entity Attribute Relations
hip
EmpID Age PhoneNo
Primary Derive Multi
Key d Valued
Attribute Attribu Attribute
Payment te
PymtID Issue

Weak Discriminati Weak


Entity ng Entity
Attribute
Role Relations
Nam
hip
E R E e R ISA

Total Role Specializati


Participati Indicator on/
on Generalizati
on
57
Summery of Symbols used in E-R diagram

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

58
Integrity Constraints
Integrity Constraints
 Integrity constraints are a set of rules. It is used to maintain the
quality of information.
 Integrity constraints ensure that the data insertion, updating, and other
processes have to be performed in such a way that data integrity is not
affected.
 Thus, integrity constraint is used to guard against accidental damage
to the database.
 Various Integrity Constraints are:
 Check
 Not null
 Unique
 Primary key
 Foreign key

60
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.

61
Integrity Constraints
 Primary key
 This constraint defines a column or combination of columns which uniquely identifies
each row in the table.
 Primary key = Unique key + 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

Dept Dept_Na Roll Student_N Dept


HOD
ID me No ame ID
Comput 101 Raj Patel 1
1 Doshi
er
102 Meet Shah 2
2 IT Vyash
62
Thank
You

You might also like