DBMS 2
DBMS 2
1 Akshay 20
2 Rahul 19
3 Pooja 20
4 Aarti 19
This complete table is referred to as “Student Entity Set” and each row represents an
“entity”.
Representation as ER Diagram-
The above table may be represented as ER diagram as-
Here,
Roll_no is a primary key that can identify each entity uniquely.
Thus, by using student’s roll number, a student can be identified uniquely.
1. Partial participation
2. Total participation
1. Partial Participation-
Partial participation is represented using a single line between the entity set and
relationship set.
2. Total Participation-
Total participation is represented using a double line between the entity set and
relationship set.
In ER diagram,
Attributes are associated with an entity set.
Attributes describe the properties of entities in the entity set.
Based on the values of certain attributes, an entity can be identified uniquely.
In this ER diagram,
Two strong entity sets “Student” and “Course” are related to each other.
Student ID and Student name are the attributes of entity set “Student”.
Student ID is the primary key using which any student can be identified uniquely.
Course ID and Course name are the attributes of entity set “Course”.
Course ID is the primary key using which any course can be identified uniquely.
Double line between Student and relationship set signifies total participation.
It suggests that each student must be enrolled in at least one course.
Single line between Course and relationship set signifies partial participation.
It suggests that there might exist some courses for which no enrollments are made.
2. Weak Entity Set-
A weak entity set is an entity set that does not contain sufficient attributes to uniquely
identify its entities.
In other words, a primary key does not exist for a weak entity set.
However, it contains a partial key called as a discriminator.
Discriminator can identify a group of entities from the entity set.
Discriminator is represented by underlining with a dashed line.
NOTE-
The combination of discriminator and primary key of the strong entity set makes it
possible to uniquely identify all entities of the weak entity set.
Thus, this combination serves as a primary key for the weak entity set.
Clearly, this primary key is not formed by the weak entity set completely.
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.
Thus,
Primary key of Apartment
= Primary key of Building + Its own discriminator
= Building number + Door number
Prepared by SKS. CSE Page 9 of 31
Differences between Strong entity set and Weak entity set-
A single rectangle is used for the A double rectangle is used for the
representation of a strong entity set. representation of a weak entity set.
It contains sufficient attributes to form its It does not contain sufficient attributes to
primary key. form its primary key.
A single line is used for the representation A double line is used for the representation
of the connection between the strong entity of the connection between the weak entity
set and the relationship. set and the relationship set.
Total participation may or may not exist in Total participation always exists in the
the relationship. identifying relationship.
Important Note-
In ER diagram, weak entity set is always present in total participation with the identifying
relationship set.
So, we always have the picture like shown here-
Example-
‘Enrolled in’ is a relationship that exists between entities Student and Course.
Relationship Set-
A relationship set is a set of relationships of same type.
Example-
Set representation of above ER diagram is-
1. Many-to-Many Cardinality-
By this cardinality constraint,
An entity in set A can be associated with any number (zero or more) of entities in set B.
An entity in set B can be associated with any number (zero or more) of entities in set A.
Symbol Used-
Example-
Consider the following ER diagram-
Here,
One student can enroll in any number (zero or more) of courses.
One course can be enrolled by any number (zero or more) of students.
Example-
Consider the following ER diagram-
Here,
One student can enroll in at most one course.
One course can be enrolled by any number (zero or more) of students.
3. One-to-Many Cardinality-
By this cardinality constraint,
An entity in set A can be associated with any number (zero or more) of entities in set B.
An entity in set B can be associated with at most one entity in set A.
Example-
Consider the following ER diagram-
Here,
One student can enroll in any number (zero or more) of courses.
One course can be enrolled by at most one student.
4. One-to-One Cardinality-
By this cardinality constraint,
An entity in set A can be associated with at most one entity in set B.
An entity in set B can be associated with at most one entity in set A.
Symbol Used-
Here,
One student can enroll in at most one course.
One course can be enrolled by at most one student.
Participation Constraints-
1. Total participation
2. Partial 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.
Symbol Used-
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.
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.
Symbol Used-
Example-
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 enrollments are made.
Relationship between Cardinality and Participation Constraints-
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.
Prepared by SKS. CSE Page 18 of 31
Attributes in ER Diagram-
Attributes are the descriptive properties which are owned by each entity of an Entity Set.
There exist a specific domain or set of values for each attribute from where the attribute
can take its values.
Types of Attributes-
In ER diagram, attributes associated with an entity set may be of the following types-
1. Simple attributes
2. Composite attributes
3. Single valued attributes
4. Multi valued attributes
5. Derived attributes
6. Key attributes
1. Simple Attributes-
Simple attributes are those attributes which can not be divided further.
Example-
Here, all the attributes are simple attributes as they can not be divided further.
Here, the attributes “Name” and “Address” are composite attributes as they are composed
of many other simple attributes.
3. Single Valued Attributes-
Single valued attributes are those attributes which can take only one value for a given
entity from an entity set.
Example-
Here, all the attributes are single valued attributes as they can take only one specific value
for each entity.
4. Multi Valued Attributes-
Multi valued attributes are those attributes which can take more than one value for a
given entity from an entity set.
Example-
Here, the attributes “Mob_no” and “Email_id” are multi valued attributes as they can take
more than one values for a given entity.
Here, the attribute “Age” is a derived attribute as it can be derived from the attribute
“DOB”.
6. Key Attributes-
Key attributes are those attributes which can identify an entity uniquely in an entity set.
Example-
Here, the attribute “Roll_no” is a key attribute as it can identify any student uniquely.
Converting ER Diagrams to Tables-
After designing an ER Diagram,
ER diagram is converted into the tables in relational model.
This is because relational models can be easily implemented by RDBMS like MySQL ,
Oracle etc.
Following rules are used for converting an ER diagram into the tables-
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.
Roll_no City
Roll_no Mobile_no
NOTE-
If we consider the overall ER diagram, three tables will be required in relational model-
One table for the entity set “Employee”
One table for the entity set “Department”
One table for the relationship set “Works in”
NOTE- Here, combined table will be drawn for the entity set B and relationship set R.
NOTE- Here, combined table will be drawn for the entity set A and relationship set R.
Case-04: For Binary Relationship With Cardinality Ratio 1:1
Here, two tables will be required. Either combine ‘R’ with ‘A’ or ‘B’
Way-01:
1. AR ( a1 , a2 , b1 )
2. B ( b1 , b2 )
Way-02:
1. A ( a1 , a2 )
2. BR ( a1 , b1 , b2 )
While determining the minimum number of tables required for binary relationships
with given cardinality ratios, following thumb rules must be kept in mind-
For binary relationship with cardinality ration m : n , separate and individual
tables will be drawn for each entity set and relationship.
For binary relationship with cardinality ratio either m : 1 or 1 : n , always
remember “many side will consume the relationship” i.e. a combined table will be
drawn for many side entity set and relationship set.
For binary relationship with cardinality ratio 1 : 1 , two tables will be required. You
can combine the relationship set with any one of the entity sets.
Rule-06: For Binary Relationship With Both Cardinality Constraints and Participation
Constraints-
Case-01: For Binary Relationship With Cardinality Constraint and Total Participation
Constraint From One Side-
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.
ER Diagrams to Tables-
Before you go through this article, make sure that you have gone through the previous
article on ER Diagrams to Tables.
After designing an ER Diagram,
ER diagram is converted into the tables in relational model.
This is because relational models can be easily implemented by RDBMS like MySQL ,
Oracle etc.
The rules used for converting an ER diagram into the tables are already discussed.
Solu
ution-
App
plying the rules, min
nimum 3 tables
t will be required-
MR1 (M1 , M2
M M , M3 , P1)
P (P1 , P2)
NR
R2 (P1 , N1
N , N2)
Pro
oblem-02::
Fin
nd the min
nimum num
mber of ta
ables requiired to rep
present the
e given ER
R diagram in
rela
ational mod
del-
Solu
ution-
App
plying the rules, min
nimum 4 tables
t will be required-
AR
R1R2 (a1 , a2 , b1 , c1)
B (b1 , b2)
C (c1 , c2)
R3
3 (b1 , c1)
Prepared by SKS. CS
SE Page 29 of
o 31
Probblem-03:
Findd the miniimum num
mber of tab
bles requirred to reprresent the given ER diagram in
rela
ational moddel-
Solu
ution-
App
plying the rules, min
nimum 5 tables
t will be required-
BR
R1R4R5 (b b1 , b2 , a1
a , c1 , d1
1)
A (a1 , a2)
R2
2 (a1 , c1)
CR
R3 (c1 , c22 , d1)
D (d1 , d2)
Pro
oblem-04::
Findd the miniimum num
mber of tab
bles requirred to reprresent the given ER diagram in
rela
ational moddel-
Sollution-
Appplying the rules, min
nimum 3 tables
t will be required-
E1 (a1 , a2)
E2
2R1R2 (b1 1 , b2 , a1 , c1 , b3)
E3
3 (c1 , c2)
Prepared by SKS. CS
SE Page 30 of
o 31
Probblem-05:
Fin
nd the min
nimum num
mber of ta
ables requiired to rep
present the
e given ER
R diagram in
rela
ational mod
del-
Sollution-
App
plying the rules thatt we have learnt, miinimum 6 tables willl be requirred-
Ac
ccount (Acc_no , Bala
ance , b_nname)
Brranch (b_n
name , b_ccity , Assetts)
Lo
oan (L_no , Amt , b_
_name)
Boorrower (C
C_name , L_no)
L
Cuustomer (C
C_name , C_street , C_city)
Depositor (C
C_name , Ac_no)
A
Prepared by SKS. CS
SE Page 31 of
o 31