Functional Dependency: The Rules Behind Your Data
A functional dependency is a rule: if you know column A, you uniquely know column B. It's the logic behind primary keys and is used for database normalization to prevent data duplication.
Why it exists
Functional dependencies exist to provide a formal, mathematical way to reason about data redundancy and integrity. Without them, database design would be pure guesswork, leading to update, insertion, and deletion anomalies where data becomes inconsistent across your system.
The mental model
Think of a functional dependency as a "lookup guarantee." If you have a table of employees, the rule "EmployeeID -> LastName" is a functional dependency. It guarantees that for any single EmployeeID, you will find exactly one LastName. The arrow means "uniquely determines". The value on the left is the determinant; the value on the right is the dependent.
How it works
We write functional dependencies as X -> Y. This means for any two rows in a table, if their values for the column(s) in set X are identical, their values for the column(s) in set Y must also be identical. For example, in a table with columns (StudentID, CourseID, Grade), the dependency {StudentID, CourseID} -> Grade holds. Given a student and a course, there is only one possible grade. However, the dependency StudentID -> Grade does not hold, because one student can have multiple grades in different courses.
When to use it
The primary use case is database normalization. By identifying all functional dependencies in your data, you can systematically decompose large, messy tables into smaller, well-structured ones. This process eliminates data redundancy and improves data integrity. It's the theoretical backbone of normal forms like 3NF and Boyce-Codd Normal Form (BCNF), which are defined by the types of functional dependencies they permit.
When not to use it
While foundational, you don't manually write out every dependency for every project. For simple schemas, good design practices often lead to normalized tables implicitly. Furthermore, in some data warehousing or analytics contexts (OLAP), denormalization is intentionally used for performance. This violates strict normalization rules to speed up read queries, making functional dependencies less of a direct design driver.
One canonical example
Consider a table: (EmployeeID, EmployeeName, DepartmentName, DepartmentHead). The dependency DepartmentName -> DepartmentHead causes redundancy. If a department has 50 employees, the department head's name is repeated 50 times. A change requires updating all 50 rows. Normalization uses the FD to split this into two tables: Employees(EmployeeID, EmployeeName, DepartmentID) and Departments(DepartmentID, DepartmentName, DepartmentHead), eliminating the redundancy.
Interview question
In the context of database design, what does the functional dependency "A -> B" primarily signify?
- a.Changes to column A automatically trigger updates in column B across all records.
- b.Column A is a foreign key that references column B.
- c.For every unique value in column A, there is exactly one corresponding value in column B.Correct
- d.Column B can be derived or calculated directly from the values in column A.
Why? this is the answer
A functional dependency A -> B means that if you know the value(s) in column A, you can uniquely determine the value(s) in column B. Option B describes a foreign key relationship, which is a different concept from functional dependency.
Just read this? Test yourself on what you have been reading.
Read the original → en.wikipedia.org
- #database
- #normalization
- #relational-model
- #data-integrity
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on database — each one lists the topics its interview covers.
See open roles