tezvyn:

Functional Dependency: The Rules Behind Your Data

AI-drafted, machine-checkedSource: Wikipedia: Functional dependencyintermediate

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.

Read the original → en.wikipedia.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.