What Is Functional Dependency?: Re Exivity: If Y Is A Subset of X, Then X Y Holds by Re Exivity Rule
What Is Functional Dependency?: Re Exivity: If Y Is A Subset of X, Then X Y Holds by Re Exivity Rule
A functional dependency is a constraint that specifies the relationship between two sets of attributes
where one set can accurately determine the value of other sets. It is denoted as X → Y, where X is a
set of attributes that is capable of determining the value of Y. The attribute set on the left side of the
arrow, X is called Determinant, while on the right side, Y is called the Dependent.
Axiom Axioms is a set of inference rules used to infer all the functional dependencies on a relational
database.
Decomposition It is a rule that suggests if you have a table that appears to contain two entities which are
determined by the same primary key then you should consider breaking them up into two different
tables.
Union It suggests that if two tables are separate, and the PK is the same, you should consider putting
them. together
1
For example, roll_no → dept_name & dept_name → dept_building, then roll_no →
dept_building is also valid.
For example,
42 abc 17
43 pqr 18
44 xyz 18
Here, {roll_no, name} → name is a trivial functional dependency, since the dependent name is a
subset of determinant set {roll_no, name}
2
2. Non-trivial Functional Dependency
In Non-trivial functional dependency, the dependent is strictly not a subset of the determinant.
For example,
42 abc 17
43 pqr 18
44 xyz 18
Here, roll_no → name is a non-trivial functional dependency, since the dependent name is not a
subset of determinant roll_no
Similarly, {roll_no, name} → age is also a non-trivial functional dependency, since age is not a subset
of {roll_no, name}
i.e. If a → {b, c} and there exists no functional dependency between b and c, then it is called a
multivalued functional dependency.
For example,
3
42 abc 17
43 pqr 18
44 xyz 18
45 abc 19
Here, roll_no → {name, age} is a multivalued functional dependency, since the dependents name &
age are not dependent on each other(i.e. name → age or age → name doesn’t exist !)
For example,
42 abc CO 4
4
43 pqr EC 2
44 xyz IT 1
45 abc EC 2
Hence, according to the axiom of transitivity, enrol_no → building_no is a valid functional dependency.
This is an indirect functional dependency, hence called Transitive functional dependency.
5
What is Normalization?
● Database normalization is the process of organizing the attributes of the database to reduce
or eliminate data redundancy (having the same data but at different places) .
● Normalization is a database design technique that reduces data redundancy and eliminates
undesirable characteristics like Insertion, Update and Deletion Anomalies.
● Normalization rules divides larger tables into smaller tables and links them using
relationships.
● The purpose of Normalisation in SQL is to eliminate redundant (repetitive) data and ensure
data is stored logically.
Objective of Normalization
1. It is used to remove the duplicate data and database anomalies from the relational table.
2. Normalization helps to reduce redundancy and complexity by examining new data types used
in the table.
3. It is helpful to divide the large database table into smaller tables and link them using
relationship.
Types of Anomalies
Following are the types of anomalies that make the table inconsistency, loss of integrity, and
redundant data.
1. Data redundancy occurs in a relational database when two or more rows or columns have the same
value or repetitive value leading to unnecessary utilization of the memory.
Student Table:
6
205 6204 James Los Angeles Economics
There are two students in the above table, 'James' and 'Ritchie Rich', whose records are repetitive
when we enter a new CourseID. Hence it repeats the studRegistration, StudName and address
attributes.
175.4K
2. Insert Anomaly: An insert anomaly occurs in the relational database when some attributes or data
items are to be inserted into the database without existence of other attributes. For example, In the
Student table, if we want to insert a new courseID, we need to wait until the student enrolled in a
course. In this way, it is difficult to insert new record in the table. Hence, it is called insertion
anomalies.
3. Update Anomalies: The anomaly occurs when duplicate data is updated only in one place and not
in all instances. Hence, it makes our data or table inconsistent state. For example, suppose there is a
student 'James' who belongs to Student table. If we want to update the course in the Student, we
need to update the same in the course table; otherwise, the data can be inconsistent. And it reflects
the changes in a table with updated values where some of them will not.
7
4. Delete Anomalies: An anomaly occurs in a database table when some records are lost or deleted
from the database table due to the deletion of other records. For example, if we want to remove Trent
Bolt from the Student table, it also removes his address, course and other details from the Student
table. Therefore, we can say that deleting some attributes can remove other attributes of the database
table.
So, we need to avoid these types of anomalies from the tables and maintain the integrity, accuracy of
the database table. Therefore, we use the normalization concept in the database management
system.
Types of Normalization
First Normal Form (1NF): If a relation contain composite or multi-valued attribute, it violates first
normal form, or a relation is in first normal form if it does not contain any composite or multi-valued
attribute. A relation is in first normal form if every attribute in that relation is singled valued attribute.
The table will be in First Normal Form (1NF) if all the attributes of the table contain only atomic
values. We can also say that if a table holds the multivalued data items in attributes or composite
8
values, the relation cannot be in the first normal form. So, we need to make it first normal form by
making the entries of the table atomic.
Example-1:
Relation STUDENT in table 1 is not in 1NF because of multi-valued attribute STUD_PHONE. Its
decomposition into 1NF has been shown in table 2.
Second Normal Form (2NF): A Relation will be in 2NF if it follows the following condition:
2. All the non-prime attributes should be fully functionally dependent on the candidate key.
4. Rule 1- Be in 1NF
9
Note – If the proper subset of candidate key determines non-prime attribute, it is called partial
dependency.
A functional dependency X --> Y is full functional dependency if removal of any attribute 'k' from X
means that the dependency does not hold any more. Full functional dependency is minimal in size.
Partial Functional Dependency Indicates that if A and B are attributes of a table, B is partially
dependent on A if there is some attribute that can be removed from A and yet the dependency still
holds.
A key is a set of attributes that uniquely identifies an entire tuple, a function dependency allow us to
Example-1:
1 C1 1000
2 C2 1500
1 C4 2000
4 C3 1000
4 C1 1000
2 C5 2000
{Note that, there are many courses having the same course fee. }
Here,
Hence,
10
COURSE_FEE would be a non-prime attribute, as it does not belong to the one only candidate key
{STUD_NO, COURSE_NO} ;
But, COURSE_NO -> COURSE_FEE, i.e., COURSE_FEE is dependent on COURSE_NO, which is a proper
subset of the candidate key. Non-prime attribute COURSE_FEE is dependent on a proper subset of
the candidate key, which is a partial dependency and so this relation is not in 2NF.
Table 1 Table 2
1 C1 C1 1000
2 C2 C2 1500
1 C4 C3 1000
4 C3 C4 2000
4 C1 C5 2000
2 C5
Note – 2NF tries to reduce the redundant data getting stored in memory. For instance, if there are
100 students taking C1 course, we dont need to store its Fee as 1000 for all the 100 records, instead
once we can store it in the second table as the course fee for C1 is 1000.
11
1. The table or relation should be in 2NF.
2. It should not contain any transitive dependency. A Transitive Dependency is that any
A relation is in 3NF if FD X determines Y ('X' -> 'Y') satisfies one of the following condition:
A relation is in third normal form, if there is no transitive dependency for non-prime attributes as well
A relation is in 3NF if at least one of the following condition holds in every non-trivial function
dependency X –> Y:
1. X is a super key.
2. Y is a prime attribute (each element of Y is part of some candidate key).
In other words,
A relation that is in First and Second Normal Form and in which no non-primary-key attribute is
transitively dependent on the primary key, then it is in Third Normal Form (3NF).
Example-1:
FD set:
12
{STUD_NO -> STUD_NAME, STUD_NO -> STUD_STATE, STUD_STATE -> STUD_COUNTRY, STUD_NO ->
STUD_AGE}
Candidate Key:
{STUD_NO}
For this relation in table 4, STUD_NO -> STUD_STATE and STUD_STATE -> STUD_COUNTRY are true.
convert it in third normal form, we will decompose the relation STUDENT (STUD_NO, STUD_NAME,
<MovieListing>
The above table is not in 3NF because it has a transitive functional dependency −
13
To form it in 3NF, you need to split the tables and remove the transitive functional dependency.
<Movie>
<Listing>
Listing_ID Listing_Type
007 Comedy
003 Action
007 Comedy
14
Boyce-Codd Normal Form (BCNF)
● A table is in BCNF if every functional dependency X → Y, X is the super key of the table.
● For BCNF, the table should be in 3NF, and for every FD, LHS is super key.
Example: Let's assume there is a company where employees work in more than one department.
EMPLOYEE table:
15
364 UK Developing D283 549
1. EMP_ID → EMP_COUNTRY
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
EMP_DEPT_MAPPING table:
EMP_ID EMP_DEPT
D394 283
D394 300
D283 232
D283 549
Functional dependencies:
1. EMP_ID → EMP_COUNTRY
Candidate keys:
Now, this is in BCNF because left side part of both the functional dependencies is a key.
17