ER Diagram
ER Diagram
This complete table is referred to as “Student Entity Set” and each row
represents an “entity”.
Representation as ER Diagram-
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.
5. For Specialization and
Generalization-
Generalization is a process of forming a
generalized super class by extracting the
common characteristics from two or more
classes.
Specialization is a reverse process of
generalization where a super class is divided
into sub classes by assigning the specific
characteristics of sub classes to them.
Generalization is the process of extracting common
properties from a set of entities and create a generalized entity from
it. It is a bottom-up approach in which two or more entities can be
generalized to a higher level entity if they have some attributes in
common.
For Example, STUDENT and FACULTY can be generalized to a higher
level entity called PERSON as shown in Figure . In this case, common
attributes like P_NAME, P_ADD become part of higher entity
(PERSON) and specialized attributes like S_FEE become part of
specialized entity (STUDENT).
In specialization, an entity is divided into sub-entities based on their
characteristics. It is a top-down approach where higher level entity is
specialized into two or more lower level entities.
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
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.
Symbols Used-
A double rectangle is used for representing a weak entity set.
A double diamond symbol is used for representing the relationship that exists between
the strong and weak entity sets and this relationship is known as identifying
relationship.
A double line is used for representing the connection of the weak entity set with the
relationship set.
Total participation always exists in the identifying relationship.
Example-
Consider the following ER diagram-
n 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.
Differences between Strong
entity set and Weak entity set-
Strong entity set Weak entity set
A single rectangle is used for the A double rectangle is used for
representation of a strong entity the representation of a weak
set. entity set.
It contains sufficient attributes to It does not contain sufficient
form its primary key. attributes to form its primary key.
A diamond symbol is used for the A double diamond symbol is used
representation of the relationship for the representation of the
that exists between the two identifying relationship that
strong entity sets exists between the strong and
weak entity set.
A single line is used for the A double line is used for the
representation of the connection representation of the connection
between the strong entity set and between the weak entity set and
the relationship. the relationship set.
Total participation may or may Total participation always exists
not exist in the relationship. in the identifying relationship.
Relationship in DBMS-
A relationship is defined as an association
among several entities.
Example-
‘Enrolled in’ is a relationship that exists
between entities Student and Course.
Relationship Set-
Roll_no City
NOTE-
Rule-04: Translating Relationship
Set into a Table- If we consider the overall ER
diagram, three tables will be
A relationship set will require one required in relational model-
table in the relational model. One table for the entity set
Attributes of the table are- “Employee”
1.Primary key attributes of the One table for the entity set
participating entity sets “Department”
2. Its own descriptive attributes if One table for the relationship
any. set “Works in”
Set of non-descriptive attributes will
be the primary key.
Emp_n Dept_i
since
o d
Rule-05: For Binary Relationships Case-01: For Binary Relationship
With Cardinality Ratios- With Cardinality Ratio m:n
Problem-02:
Find the minimum number of tables required to represent the given
ER diagram in relational model-
Solution-1
Applying the rules, minimum 3 tables will be required-
MR1 (M1 , M2 , M3 , P1) ,P (P1 , P2) ,NR2 (P1 , N1 , N2)
Solution-2
Applying the rules, minimum 4 tables will be
required-
AR1R2 (a1 , a2 , b1 , c1) ,B (b1 , b2), C (c1 , c2), R3
(b1 , c1)
Problem-03:
Find the minimum
number of tables
required to represent
the given ER diagram
in relational model
Solution-
Applying the rules that we have
learnt, minimum 6 tables will be
required-
Account (Ac_no , Balance , b_name)
Branch (b_name , b_city , Assets)
Loan (L_no , Amt , b_name)
Borrower (C_name , L_no)
Customer(C_name ,C_street , c_city)
Depositor (C_name , Ac_no)
Constraints in DBMS-
Relational constraints are the restrictions imposed on the database
contents and operations.
They ensure the correctness of data in the database.
Types of Constraints in DBMS-
In DBMS, there are following 5 different types of relational constraints-
1. Domain Constraint- 2. Tuple Uniqueness
Constraint-
Domain constraint defines the
domain or set of values for an Tuple Uniqueness constraint
attribute. specifies that all the tuples must
It specifies that the value taken by be necessarily unique in any
Example-01: Consider the following
the attribute must be the atomic relation.
Student table
value from its domain.
Example- Consider the following Student STU_I
Name Age
D
table-
STU_
ID
Name Age S00
Akshay 20
1
S00
Akshay 20 S00
1 Abhishek 21
2
S00 Abhishe
21 S00 Shashan
2 k 20
3
This relation k
satisfies the tuple
S00 Shasha uniqueness constraint since here
20 S00
3 nk all the tuplesRahul
are unique.20
Here, value ‘A’ is not allowed since 4
S00
only integerRahul
values canA be taken by
4
the age attribute.
Example-02: Consider the following 3. Key Constraint-
Student table- Key constraint specifies that in any
STU_I
relation-
Name Age
D 1.All the values of primary key must
be unique.
S00
Akshay 20 2.The value of primary key must not
1
be null.
Example-
S00 Consider the following Student
Akshay 20
1 table- STU_I
Name Age
D
S00 Shashan
20
3 k S00
This relation does not satisfy Akshay 20
1
the
S00tuple uniqueness
Rahul 20
4
constraint since here all the S00 Abhishe
21
tuples are not unique. 1 k
S00 Shashan
20
3 k
This relation does not satisfy the key
constraint
S00as here all the values of
Rahul 20
primary 4key are not unique
4. Entity Integrity Constraint- 5. Referential Integrity
Constraint-
Entity integrity constraint specifies
that no attribute of primary key must This constraint is enforced when a
contain a null value in any relation. foreign key references the primary
This is because the presence of null key of a relation.
value in the primary key violates the It specifies that all the values
uniqueness property. taken by the foreign key must
either be available in the relation
Example- of the primary key or be null.
Consider the following Student Important Results-
table-
STU_I
Name Age
D The following two important results
S00 emerges out due to referential
Akshay 20 integrity constraint-
1
1.We can not insert a record into a
S00 Abhishe referencing relation if the
21
2 k corresponding record does not exist
in the referenced relation.
S00 Shashan
20 2.We can not delete or update a
This3relationkdoes not satisfy the
record of the referenced relation if
entity integrity constraint as here the
Rahul 20 the corresponding record exists in
primary key contains a NULL value.
the referencing relation.
Here,
Example- The relation ‘Student’ does
Consider the following two relations- not satisfy the referential
‘Student’ and ‘Department’. integrity constraint.
Here, relation ‘Student’ references This is because in relation
the relation ‘Department’. ‘Department’, no value of
primary key specifies
department no. 14.
Thus, referential integrity
constraint is violated.
STU_I Dept_na
Name Dept_no Dept_no
D me
CS Computer Science
1 Rahul 22 CS
EE Electronics Engineering
2 Anjali 21 CS
IT Information Technology
3 Teena 20 IT
CE Civil Engineering
Here,
In relation “Student”, we can not insert any student having branch code
ME (Mechanical Engineering).
This is because branch code ME is not present in the relation “Branch”.
Cause-02: Deletion from a Referenced Relation-
Example-
The violation caused due to a deletion from the referenced relation can
be handled in the following three ways-
Method-01:
Method-03:
This method involves setting the value being deleted from the
referenced relation to NULL or some other value in the referencing
relation if the referencing attribute uses that value.
use-03: Updation in a Referenced Relation-
Method-01:
Method-02:
Method-03:
This method involves setting the value being updated in the referenced
relation to NULL or some other value in the referencing relation if the
referencing attribute uses that value.
Closure of an Attribute Set-
A+ = { A }
={A,B,C} ( Using A → BC )
={A,B,C,D,E} ( Using BC → DE )
={A,B,C,D,E,F} ( Using D → F )
= { A , B , C , D , E , F , G } ( Using CF → G ) Thus,
A+ = { A , B , C , D , E , F , G }
Closure of attribute D-
D+ = { D }
= { D , F } ( Using D → F )
We can not determine any other attribute using attributes D and F
contained in the result set.
Thus,
D+ = { D , F }
{ B , C }+ = { B , C }
={B,C,D,E} ( Using BC → DE )
={B,C,D,E,F} ( Using D → F )
={B,C,D,E,F,G} ( Using CF → G ) Thus, { B , C }+ = { B , C ,
Finding the Keys Using Closure-
Super Key-
If the closure result of an attribute set contains all the attributes of the
relation, then that attribute set is called as a super key of that relation.
Thus, we can say-
“The closure of a super key is the entire relation schema.”
Example-
In the above example,
The closure of attribute A is the entire relation schema.
Thus, attribute A is a super key for that relation.
Candidate Key-
If there exists no subset of an attribute set whose closure contains all the
attributes of the relation, then that attribute set is called as a candidate
key of that relation.
Example-
In the above example,
No subset of attribute A contains all the attributes of the relation.
Thus, attribute A is also a candidate key for that relation.
PRACTICE PROBLEM BASED ON FINDING CLOSURE OF
AN ATTRIBUTE SET-
Problem-
Option-(A):
{ CF }+ = { C , F }
={C,F,G} ( Using C → G )
={C,E,F,G} ( Using F → E )
={A,C,E,E,F} ( Using G → A )
={A,C,D,E,F,G } ( Using AF → D )
Since, our obtained result set is same as the given result set, so, it means it is correctly given.
Option-(B):
{ BG }+ = { B , G }
={A,B,G } ( Using G → A )
={A,B,C,D,G } ( Using AB → CD )
Since, our obtained result set is same as the given result set, so, it means it is correctly given.
Option-(C):
{ AF }+ = { A , F }
={A,D,F} ( Using AF → D )
={A,D,E,F} ( Using F → E )
Since, our obtained result set is different from the given result set, so,it means it is not correctly given.
Option-(D):
{ AB }+ = { A , B }
={A,B,C,D} ( Using AB → CD )
={A,B,C,D,G } ( Using C → G )
Since, our obtained result set is different from the given result set, so,it means it is not correctly given.
Thus,
Option (C) and Option (D) are correct.
Different Types Of Keys in The terms ‘relation’ and ‘table’ are used
DBMS- interchangeably.
There are following 10 important The terms ‘tuple’ and ‘record’ are used
keys in DBMS- interchangeably.
1. Super Key- 2. Candidate Key-
A super key is a set of attributes that A minimal super key is called as a
can identify each tuple uniquely in the candidate key.
given relation.
A super key is not restricted to have A set of minimal attribute(s) that
any specific number of attributes. can identify each tuple uniquely
Thus, a super key may consist of any in the given relation is called as a
number of attributes. candidate key.
Example-
Example-
Consider the following Student Consider the following Student
schema- schema-
Student ( roll , name , sex , age , Student ( roll , name , sex , age
address , class , section ) , address , class , section )
Given below are the examples of super Given below are the examples of
keys since each set can uniquely candidate keys since each set
identify each student in the Student consists of minimal
table- attributes required to identify
( roll , name , sex , age , address , each student uniquely in the
class , section ) Student table-
( class , section , roll ) All the attributes in a( class
super, key
section , roll )
are definitely
sufficient
(class , section , roll , sex ) to identify (each
name , address
tuple ) in the
uniquely
( name , address ) given relation but all of them may not be
NOTES-
A primary key is a candidate key that the database designer selects while
designing the database.
OR
Candidate key that the database designer implements is called as a
primary key.
NOTES-
5. Foreign Key-
An attribute ‘X’ is called as a foreign key to some other attribute ‘Y’ when
its values are dependent on the values of attribute ‘Y’.
The attribute ‘X’ can assume only those values which are assumed by the
attribute ‘Y’.
Here, the relation in which attribute ‘Y’ is present is called as
the referenced relation.
The relation in which attribute ‘X’ is present is called as the referencing
relation.
Example- Consider the following
two schemas-
Here, t_dept can take only those values which are present in dept_no in
Department table since only those departments actually exist.
NOTES-
Dependent_na
Emp_no Relation
me
E1 Suman Mother
E1 Ajay Father
E2 Vijay Father
E2 Ankush Son
7. Composite Key-
A primary key comprising of multiple attributes and not just a single attribute is called as a
composite key.
8. Unique Key-
Example-
Example-
Mobile Number of students in a class where every student owns a mobile phone.
Secondary key is required for the indexing purpose for better and faster searching.
Functional Dependency-
α β
t1[α] t1[β]
t2[α] t2[β]
……. …….
fd : α → β
Types Of Functional Dependencies-
There are two types of functional dependencies-
Reflexivity-
If B is a subset of A, then A → B always holds.
Transitivity-
If A → B and B → C, then A → C always holds.
Augmentation-
If A → B, then AC → BC always holds.
Decomposition-
If A → BC, then A → B and A → C always holds.
Composition-
If A → B and C → D, then AC → BD always holds.
Additive-
If A → B and A → C, then A → BC always holds.