F - DataBase Chapter - 4
F - DataBase Chapter - 4
F - DataBase Chapter - 4
The functional dependency is a relationship that exists between two attributes. It typically
exists between the primary key and non-key attribute within a table. X → Y
The left side of FD is known as a determinant, the right side of the production is known
as a dependent.
For example:
Here Emp_Id attribute can uniquely identify the Emp_Name attribute of employee table
because if we know the Emp_Id, we can tell that employee name associated with it.
1. Emp_Id → Emp_Name
Dependencies in DBMS is a relation between two or more attributes. It has the following
types in DBMS −
Fully-Functional Dependency
Multivalued Dependency
Partial Dependency
Transitive Dependency
Functional Dependency
If the information stored in a table can uniquely determine another information in the same
table, then it is called Functional Dependency. Consider it as an association between two
attributes of the same relation.
If P functionally determines Q, then
P -> Q
Let us see an example −
<Employee>
EmpID EmpName EmpAge
E01 Amit 28
E02 Rohit 31
1
Chapter 4 Fundamentals of Database Systems
Fully-functionally Dependency
An attribute is fully functional dependent on another attribute, if it is Functionally
Dependent on that attribute and not on any of its proper subset.
For example, an attribute Q is fully functional dependent on another attribute P, if it is
Functionally Dependent on P and not on any of the proper subset of P.
Let us see an example −
<EmployeeProject>
EmpID ProjectID Days (spent on the project)
E099 001 320
E056 002 190
Whereas the subset {EmpID, ProjectID} can easily determine the {Days} spent on the
project by the employee.
This summarizes and gives our fully functional dependency −
{EmpID, ProjectID} -> (Days)
Multivalued Dependency
When existence of one or more rows in a table implies one or more other rows in the same
table, then the Multi-valued dependencies occur.
If a table has attributes P, Q and R, then Q and R are multi-valued facts of P.
It is represented by double arrow −
->->
2
Chapter 4 Fundamentals of Database Systems
Partial Dependency
Partial Dependency occurs when a nonprime attribute is functionally dependent on part of
a candidate key.
u Partial Dependency – when an non-key attribute is determined by a part, but not
the whole, of a COMPOSITE primary key.
The 2nd Normal Form (2NF) eliminates the Partial Dependency. Let us see an example −
<StudentProject>
StudentID ProjectNo StudentName ProjectName
S01 199 Katie Geo Location
S02 120 Ollie Cluster Exploration
In the above table, we have partial dependency; let us see how −
The prime key attributes are StudentID and ProjectNo.
As stated, the non-prime attributes i.e. StudentName and ProjectName should be
functionally dependent on part of a candidate key, to be Partial Dependent.
The StudentName can be determined by StudentID that makes the relation Partial
Dependent.
The ProjectName can be determined by ProjectID, which that the relation Partial
Dependent.
Transitive Dependency
When an indirect relationship causes functional dependency it is called Transitive
Dependency.
If P -> Q and Q -> R is true, then P-> R is a transitive dependency.
Transitive Dependency – when a non-key attribute determines another non-key attribute.
3
Chapter 4 Fundamentals of Database Systems
Types of Functional dependency
Example:
Example:
1. ID → Name,
2. Name → DOB
4
Chapter 4 Fundamentals of Database Systems
Anomalies in DBMS
The type of problems that could occur in insufficiently normalized table is called
anomalies
There are three types of anomalies that occur when the database is not normalized. These
are – Insertion, update and deletion anomaly. Let’s take an example to understand this.
In update anomaly, the data cannot be updated correctly because the same values occur
multiple times in a column and in delete anomaly the deletion of a record creates
inconsistency as it gets deleted from more than one row. So the aim of normalization is to
remove redundant data as well as storing only related data in the table. This decreases the
database size and the data gets logically stored in the database.
Update anomaly: In the above table we have two rows for employee Rick as he belongs
to two departments of the company. If we want to update the address of Rick then we
have to update the same in two rows or the data will become inconsistent. If somehow,
the correct address gets updated in one department but not in other then as per the
database, Rick would be having two different addresses, which is not correct and would
lead to inconsistent data.
5
Chapter 4 Fundamentals of Database Systems
Insert anomaly: Suppose a new employee joins the company, who is under training and
currently not assigned to any department then we would not be able to insert the data into
the table if emp_dept field doesn’t allow nulls.
Delete anomaly: Suppose, if at a point of time the company closes the department D890
then deleting the rows that are having emp_dept as D890 would also delete the
information of employee Maggie since she is assigned only to this department.
To overcome these anomalies we need to normalize the data. In the next section we will
discuss about normalization.
Normalization is the process of identifying the logical associations between data items
and designing a database that will represent such associations but without suffering the
anomalies which are;
1. Insertion Anomalies
2. Deletion Anomalies
3. Modification Anomalies
Normalization may reduce system performance since data will be cross referenced from
many tables. Thus denormalization is sometimes used to improve performance, at the cost
of reduced consistency guarantees.
All the normalization rules will eventually remove the anomalies that may exist during data
manipulation after the implementation.
The type of problems that could occur in insufficiently normalized table is called anomalies
which includes;
6
Chapter 4 Fundamentals of Database Systems
human fallibility being what it is, some of the needed additional insertions may be
missed. In other words, due to human fallibility, additional insertions may be missed.
(2) Deletion anomalies
A "deletion anomaly" is a failure to remove information about an existing database
entry when it is time to remove that entry. In a properly normalized database,
information about an old, to-be-gotten-rid-of entry needs to be deleted from only one
place in the database; in an inadequately normalized database, information about that
old entry may need to be deleted from more than one place, and, human fallibility being
what it is, some of the needed additional deletions may be missed.
(3) Modification/Updating anomalies
A modification of a database involves changing some value of the attribute of a table.
In a properly normalized database table, whatever information is modified by the user,
the change will be effected and used accordingly.
N.B: The purpose of normalization is to reduce the chances for anomalies to occur in a database.
Normalization
7
Chapter 4 Fundamentals of Database Systems
Normal Description
Form
2NF A relation will be in 2NF if it is in 1NF and all non-key attributes are fully functional depe
on the primary key.
As per the rule of first normal form, an attribute (column) of a table cannot hold
multiple values.
It should hold only atomic values.
There are no duplicated rows in the table. Unique identifier.
Each cell is single-valued (i.e., there are no repeating groups).
Entries in a column (attribute, field) are of the same kind.
8
Chapter 4 Fundamentals of Database Systems
Example 1: for First Normal Form (1NF): Consider the following unnormalized database table.
Remove all repeating groups. Distribute the multi-valued attributes into different rows and identify
a unique identifier for the relation so that is can be said is a relation in relational database.
9
Chapter 4 Fundamentals of Database Systems
Remember you can add additional fields/attributes in normalizing database tables. As you
can see in the above SkillID is added to organize the database table effectively and
efficiently.
Example2: Suppose a company wants to store the names and contact details of its
employees. It creates a table that looks like this:
8812121212
102 Jon Kanpur
9900012222
9990000123
104 Lester Bangalore
8123450987
Two employees (Jon & Lester) are having two mobile numbers so the company stored
them in the same field as you can see in the table above.
This table is not in 1NF as the rule says “each attribute of a table must have atomic
(single) values”, the emp_mobile values for employees Jon & Lester violates that rule.
emp_id emp_name emp_address emp_mobile
10
Chapter 4 Fundamentals of Database Systems
Example: Let's assume, a school can store the data of teachers and the subjects they teach.
In a school, a teacher can teach more than one subject.
TEACHER table
25 Chemistry 30
25 Biology 30
47 English 35
83 Math 38
83 Computer 38
Candidate Keys: {teacher_id, subject}
Non-prime attribute: teacher_age
The table is in 1 NF because each attribute has atomic values. However, it is not in 2NF
because non-prime attribute teacher_age is dependent on teacher_id alone which is a
proper subset of candidate key. This violates the rule for 2NF as the rule says “no non-
prime attribute is dependent on the proper subset of any candidate key of the table”.
To make the table complies with 2NF we can break it in two tables like this:
teacher_details table:
To convert the given table into 2NF, we decompose it into two tables:
11
Chapter 4 Fundamentals of Database Systems
TEACHER_DETAIL table:
TEACHER_ID TEACHER_AGE
25 30
47 35
83 38
TEACHER_SUBJECT table:
TEACHER_ID SUBJECT
25 Chemistry
25 Biology
47 English
83 Math
83 Computer
o A relation will be in 3NF if it is in 2NF and not contain any transitive partial
dependency.
o 3NF is used to reduce the data duplication. It is also used to achieve the data
integrity.
o If there is no transitive dependency for non-prime attributes, then the relation must
be in third normal form.
o third normal form (3NF): the relation must be in 2NF and
o all transitive dependencies must be removed; a non-key attribute may not be
functionally dependent on another non-key attribute
Example for Third Normal Form (3NF): Consider the following example: Students of same
batch (same year) live in one building or dormitory.
12
Chapter 4 Fundamentals of Database Systems
STUDENT
o
o This schema is in its 2NF since the primary key is a single attribute.
o Let’s take StudID, Year and Dormitary and see the dependencies.
o StudIDYear AND YearDormitary
o And Year cannot determine StudID and Dormitary cannot determine StudID. Then
transitively StudIDDormitary.
o To convert it to a 3NF we need to remove all transitive dependencies of non-key attributes
on another non-key attribute.
o The non-primary key attributes, dependent on each other will be moved to another table
and linked with the main table using candidate key- foreign key relationship.
13
Chapter 4 Fundamentals of Database Systems
O STUDENT DORM
StudID Stud F_Name Stud L_Name Dep’t Year Year Dormitary
A relation is in third normal form if it holds at least one of the following conditions for every non-
trivial function dependency X → Y.
1. X is a super key.
2. Y is a prime attribute, i.e., each element of Y is part of some candidate key.
Example:
EMPLOYEE_DETAIL table:
Non-prime attributes: In the given table, all attributes except EMP_ID are non-prime.
14
Chapter 4 Fundamentals of Database Systems
That's why we need to move the EMP_CITY and EMP_STATE to the new
<EMPLOYEE_ZIP> table, with EMP_ZIP as a Primary key.
EMPLOYEE table:
EMPLOYEE_ZIP table:
201010 UP Noida
02228 US Boston
60007 US Chicago
06389 UK Norwich
462007 MP Bhopal
15
Chapter 4 Fundamentals of Database Systems
Example: Let's assume there is a company where employees work in more than one department.
EMPLOYEE table:
1. EMP_ID → EMP_COUNTRY
2. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
The table is not in BCNF because neither EMP_DEPT nor EMP_ID alone are keys.
To convert the given table into BCNF, we decompose it into three tables:
EMP_COUNTRY table:
EMP_ID EMP_COUNTRY
264 India
264 India
EMP_DEPT table:
16
Chapter 4 Fundamentals of Database Systems
EMP_DEPT_MAPPING table:
EMP_ID EMP_DEPT
D394 283
D394 300
D283 232
D283 549
Functional dependencies:
1. EMP_ID → EMP_COUNTRY
2. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
Now, this is in BCNF because left side part of both the functional dependencies is a key.
17