Functional Dependency
Functional Dependency (FD) is a fundamental concept in relational databases used to describe the relationship between attributes (columns) of a relation (table). It helps identify how data is connected and plays a crucial role in normalization, which is the process of organizing data to reduce redundancy.
What is a Functional Dependency?
In simple terms:
Â
If you know the value of one attribute (or a set of attributes), and you can uniquely determine the value of another attribute, then there is a functional dependency.
Â
We write this as:
Â
This means:
- Attribute A functionally determines attribute B.
- For every value of A, there is exactly one corresponding value of B.
Example:
Consider this table:
StudentID | Name | Department |
---|---|---|
101 | Anya | CS |
102 | Rahul | IT |
103 | Sneha | CS |
Here:
StudentID → Name
(StudentID uniquely determines Name)StudentID → Department
(StudentID uniquely determines Department)
Â
So, StudentID
is the determinant, and Name
and Department
are dependent attributes.
Â
But:
Department → Name
is not a valid FD, because multiple students can be in the same department.
Types of Functional Dependencies:
Trivial FD
- If B is a subset of A:
A → B
is trivial.
Example:{StudentID, Name} → Name
Â
Non-trivial FD
- If B is not a subset of A.
Example:StudentID → Name
Â
Fully Functional Dependency
- B depends on the entire set of A, not just a part.
Used in 2NF.
Example:{RollNo, Course} → Grade
But not justRollNo → Grade
Â
Transitive Dependency
- A → B and B → C, then A → C
Used to eliminate 3NF issues.
Example:StudentID → DepartmentID
,DepartmentID → DepartmentName
,
So,StudentID → DepartmentName
(transitive)
Why Functional Dependency Matters
Functional dependencies help us identify candidate keys.
Â
They are the foundation for normalization, which ensures that:
- Data is organized efficiently.
- Redundancy is minimized.
- Update anomalies are reduced.