3cs518ic24 Dbms Minor - Unit 2 (B)
3cs518ic24 Dbms Minor - Unit 2 (B)
( ER – Model)
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
Design phase
we use diagram
High Level view to explain what ER Model
are the things in
your database
4
Components of ER diagram
An ER diagram is mainly composed of following three components-
1. Entity
2. Attributes
3. Relationship
5
Consider the following Student table-
Here,
This complete table is referred to • Roll_no is a primary key that
as “Student Entity Set” and each can identify each entity
row represents an “entity”. uniquely.
• Thus, by using student’s roll
number, a student can be
identified uniquely.
6
Project
1.Collect the information(verbal description from client)diagram
2.Noun Entity{ a person owns a car : person}
3.Verb relationship{ a employee works for department}, any verb going to
describe is relationship
4.Noun describes noun attribute {property of the entity}
7
1(a). 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 bank
se database.
Exerci Write down the different entities of hospital
se database.
8
1(b) 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
9
Example
An entity is an object that exists and is distinguishable from other
objects.
Example: specific person, company, event, plant
An entity type or set is a set of entities of the same type that share the
same properties.
Example: set of all persons, companies, trees, holidays
10
2. 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
Works_f
Employee or Department
12
E-R Diagram of a Library System
Primary Primary
Key Attribut Key
es
RollNo Name Relationsh BookN
Name
o
ip
13
Ternary Relationship
ProjectI Project
D Name
Project
Technolo
Branch Branch Sem
gy
15
Types of Attributes
16
Types of Attributes
17
Types of Attributes
18
Summary
19
Entity with all types of Attributes
Middle
First Name
Last
Key Name Name
attribute
Composit Apartme
RollNo Name e nt
Composit
Derived
e
Multiple
Value Phone Birth
Date Area
No
Single Simple
Value
20
Descriptive Attribute
Attributes of the relationship is called descriptive attribute.
Descripti
ve
Attribute
Issue
BookN
RollNo Name Date Name
o
21
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
22
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:
a) One to Many
b) Many to One
c) Many to Many
23
a) One to Many(1:N)
Verbal Description: Every Employee works for exactly one department, and a department can
have many employee, new department need not have a employee. (RA phase)
• e1
• e2 • d1 Degree: 2
• e3 Max card: e(1),
• e4 • d2 d(N)
• e5 Min card:
• e6 • d3 e(1)
Every ,d(0)
relation in relation set is actually an
association between employee set and
department set
cardinality: (1)
(N)
Degree: In relationship how many entity set are
participation:(1)
participating
(0)
Cardinality ratio(max card): Maximum no of relationship a entity
can participate
Participation(min card): Minimum no of relationship in each an entity can
participate
ationship in a relationship set is an association between employee and department
to make ER diagram as readable as possible
lso take department first: a department employs an employee
24
Verbal Description: Every Employee works for exactly one department, and a
department can have many employee, new department need not have a employee. (RA
phase)
Participation
Total participation using double line(min.
card=1)
partial participation using single line(min.
card=0)
Works_for
dinality 1 N
25
Min Max Representation
26
Participation
1.Total Participation- :
• It specifies that each entity in the entity set must compulsorily participate in at least
one relationship instance in that relationship set.
• That is why, it is also called as mandatory participation.
• Total participation is represented using a double line between the entity set and
relationship set.
Here,
• Double line between the entity set “Student” and relationship set “Enrolled in”
signifies total participation.
• It specifies that each student must be enrolled in at least one course.
27
Participation
2. Partial Participation-
• It specifies that each entity in the entity set may or may not participate in the
relationship instance in that relationship set.
• That is why, it is also called as optional participation.
• Partial participation is represented using a single line between the entity set and
relationship set.
Here,
Single line between the entity set “Course” and relationship set “Enrolled in”
signifies partial participation.
It specifies that there might exist some courses for which no enrolment's are made.
Minimum cardinality tells whether the participation is partial or total.
If minimum cardinality = 0, then it signifies partial participation.
If minimum cardinality = 1, then it signifies total participation.
Maximum cardinality tells the maximum number of entities that participates in a
relationship set.
28
One to One(1:1)
RA: Every department should have a manager and only one employee
manages department and an employee manages only one department.
Employee Manages Department
• e1 .
• • d1
•
e2
e3
.
• e4 . • d2
• e5
• e6 • d3
Cardinality: 1 1
Participation: 0 1
manages
Works_on
Employee M N
Project
30
Recursive relationship
RA : Every employee suppose to report only one employee(boss or
supervisor), an employee
can supervise one or more employee. It is not necessary that every
employee has to manage
someone.
Degree=2
31
Attribute to relation
32
Weak Entity
On the basis of requirement analysis we identified the key attribute, some
times we might not have a key attribute at all.
Example: Every dependent is associated with one employee, but some
employee may not have any dependent.
33
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
Weak
Strong Entity Weak
Entity Set Relationsh Entity Set
ip
35
Example
In this ER diagram,
• One strong entity set “Building” and one weak entity set “Apartment” are
related to each other.
• Strong entity set “Building” has building number as its primary key.
• Door number is the discriminator of the weak entity set “Apartment”.
• This is because door number alone can not identify an apartment uniquely as
there may be several other buildings having the same door number.
• Double line between Apartment and relationship set signifies total participation.
• It suggests that each apartment must be present in at least one building.
• Single line between Building and relationship set signifies partial participation.
• It suggests that there might exist some buildings which has no apartment.
• To uniquely identify any apartment,
• First, building number is required to identify the particular building.
• Secondly, door number of the apartment is required to uniquely identify
the apartment.
38
Strong vs Weak Entity
Strong entity set Weak entity set
A single rectangle is used for the representation of a A double rectangle is used for the representation of a
strong entity set. weak entity set.
A diamond symbol is used for the representation of the A double diamond symbol is used for the
relationship that exists between the two strong entity representation of the identifying relationship that
sets. exists between the strong and weak entity set.
A single line is used for the representation of the A double line is used for the representation of the
connection between the strong entity set and the connection between the weak entity set and the
relationship. relationship set.
Total participation may or may not exist in the Total participation always exists in the identifying
relationship. relationship.
39
Exercise 1
Draw an ER diagram for Sony Music Company, which store information about musicians
who perform on its albums (as well as other company data) in a database.
Each musician that records at SonyMusic has an SSN, a name, an address, and a phone
number.
Each instrument used in songs recorded at SonyMusic has a unique identification
number, a name (e.g., guitar, synthesizer, flute) and a musical key (e.g., C, B-flat, E-flat).
Each album recorded on the SonyMusic label has a unique album identifier, a title, a
copyright date, a format (e.g., CD or MC).
Each song recorded at SonyMusic has a title and an author.
Each musician may play several instruments, and a given instrument may be played by
several musicians.
Each album has a number of songs on it, but no song may appear on more than one
album.
Each song is performed by one or more musicians, and a musician may perform a
number of songs.
Each album has exactly one musician who acts as its producer. A musician may produce
several albums, of course.
40
Solution
41
Exercise 2
Draw an ER diagram for the given scenario;
Suppose that you are designing a schema to record information about reality shows on
TV. Your database needs to record the following information:
For each reality show, its name, genre, basic-info and participants name. Any reality
show has at least two or more participants.
For each producer, the company name, company country. A show is produced by exactly
one producer. And one producer produces exactly one show.
For each television, its name, start year, head office. A television may broadcasts
multiple shows. Each show is broadcasted by exactly one television.
For each user, his/her username, password, and age. A user may rate multiple shows,
and a show may be rated by multiple users. Each rating has a score of 0 to 10.
Draw an entity relationship diagram for this database.
42
Solution
43
Exercise 3
Consider the following requirements list:
The university offers one or more programs.
A program is made up of one or more courses.
A student must enroll in a program.
A student takes the courses that are part of her program.
A program has a name, a program identifier, the total credit points required to graduate,
and the year it commenced.
A course has a name, a course identifier, a credit point value, and the year it
commenced.
Students have one or more given names, a surname, a student identifier, a date of birth,
and the year they first enrolled. We can treat all given names as a single object—for
example, “John Paul.”
When a student takes a course, the year and semester he attempted it are recorded.
When he finishes the course, a grade (such as A or B) and a mark (such as 60 percent)
are recorded.
Each course in a program is sequenced into a year (for example, year 1) and a semester
(for example, semester 1).
44
Solution
45
Exercise 4
Consider the following requirements list:
• The airline has one or more airplanes.
• An airplane has a model number, a unique registration number, and the capacity to take one
or more passengers.
• An airplane flight has a unique flight number, a departure airport, a destination airport, a
departure date and time, and an arrival date and time.
• Each flight is carried out by a single airplane.
• A passenger has given names, a surname, and a unique email address.
• A passenger can book a seat on a flight.
46
Solution
47
Exercise 5
• Suppose you are given the following requirements for a simple database for the National Hockey League
(NHL):
• the NHL has many teams.
• each team has a name, a city, a coach, a captain, and a set of players.
• each player belongs to only one team.
• each player has a name, a position (such as left wing or goalie), a skill level, and a set of injury records.
• a team captain is also a player.
• a game is played between two teams (referred to as host_team and guest_team) and has a date (such as May
11th, 1999) and a score (such as 4 to 2).
• Construct a clean and concise ER diagram for the NHL database.
48
Solution
49
Exercise 6
Consider a car-insurance company:
• Each customer or person have their name, address and unique driver id.
• Each car is having model, year and licence no.
• While each accident which is reported in terms of location, date and report
no.
• Each customers own one or more cars.
• Each car has associated with it zero to any number of recorded accidents.
50
Solution
51
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
52
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
53
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.
54
Generalization & Specialization example
Nam Addres
e s
PID City
Person
IS
A
Salar Balan
Employee Customer
y ce
IS
A
Days Hour
Worked Worked
55
Aggregation
Aggregation is a process in which a single entity alone is not able to make sense in a
relationship so the relationship of two entities acts as one entity.
Custom
Company
er
Work
Employee Department
s
Customer
Can not connect two
relationship
Borro
Borrow
w
Loan Loan
57
Conversion of ER model to Relational model
Rule-01: For Strong Entity Set With Only Simple
Attributes-
A strong entity set with only simple attributes will require only one table in
relational model.
• Attributes of the table will be the attributes of the entity set.
• The primary key of the table will be the key attribute of the entity set.
58
Rule-02: For Strong Entity Set With Composite
Attributes-
• A strong entity set with any number of composite attributes will require only one
table in relational model.
• We will create column for components of composite attribute only.
59
Rule-03: For Strong Entity Set With Multi Valued Attributes-
A strong entity set with any number of multi valued attributes will require two
tables in relational model.
• One table will contain all the simple attributes with the primary key.
• Other table will contain the primary key and all the multi valued attributes.
60
Rule-04: Translating Relationship Set into
a Table-
A relationship set will require one table in the relational model.
Attributes of the table are-
• Primary key attributes of the participating entity sets
• Its own descriptive attributes if any.
Set of non-descriptive attributes will be the primary key.
Weak entity are converted into tables of their own with primary key of strong entity acting
as foreign key in the table.
• Composite prime attribute of the table= FK + attribute of WE
Weak entity set always appears in association with identifying relationship with total
participation constraint.
Emp Project
Here, three tables will be required-
1.A ( a1 , a2 ) If relationship
2.R ( a1 , b1 ) attribute(start_date)
3.B ( b1 , b2 ) Will be in the relationship table
63
Case-02: For Binary Relationship With Cardinality Ratio
1:n
64
Case-04: For Binary Relationship With Cardinality Ratio 1:1
Emp Dept
manages
Here, two tables will be required. Either combine ‘R’ with ‘A’ or ‘B’
Way-01:
• AR ( a1 , a2 , b1 )
• B ( b1 , b2 )
Way-03:
• A( a1 , a2 )
• B ( b1 , b2 )
• R (a1, b1) primary key(a1 or b1)
65
Rule-06: For Binary Relationship With Both Cardinality Constraints and
Participation Constraints-
Because cardinality ratio = 1 : n , so we will combine the entity set B and relationship set R.
Then, two tables will be required-
1.A ( a1 , a2 )
2.BR ( a1 , b1 , b2 )
Because of total participation, foreign key a1 has acquired NOT NULL constraint, so it can’t be null now.
66
Case-02: For Binary Relationship With Cardinality Constraint and Total
Participation Constraint From Both Sides-
If there is a key constraint from both the sides of an entity set with total participation, then
that binary relationship is represented using only single table.
67
Exercise
Problem-01:
Find the minimum number of tables required for the following ER diagram in relational
model-
68
Problem-02:
Find the minimum number of tables required to represent the given ER diagram in
relational model-
R3 M:N
Find the minimum number of tables required to represent the given ER diagram in
relational model-
Find the minimum number of tables required to represent the given ER diagram in relational
model-
71
Problem-05:
Find the minimum number of tables required to represent the given ER diagram in
relational model-
72
Problem 6
73
Summery of Symbols used in E-R diagram