Explain why a given set of database tables are, or are not, in 3NF

Resources | Subject Notes | Computer Science

Database Concepts: 3NF

This section explains the concept of Third Normal Form (3NF) in database design and how to determine if a set of database tables adheres to this normal form. Understanding 3NF is crucial for designing efficient and data-integrity-focused database schemas.

What is Normal Form?

Normalization is a database design technique that organizes data to reduce redundancy and improve data integrity. It involves dividing larger tables into smaller, more manageable tables and defining relationships between them. Each normal form (1NF, 2NF, 3NF, etc.) builds upon the previous one, imposing stricter rules on the structure of the tables.

Third Normal Form (3NF)

A table is in 3NF if it meets the following conditions:

  1. It is in 2NF.
  2. No non-key attribute is transitively dependent on the primary key.

Let's break down these conditions:

  1. 2NF: A table is in 2NF if it is in 1NF and all non-key attributes are fully functionally dependent on the entire primary key. This means that no non-key attribute depends only on a portion of the primary key.
  2. Transitive Dependency: A transitive dependency occurs when a non-key attribute depends on another non-key attribute, which in turn depends on the primary key. In simpler terms, if A -> B and B -> C, then A transitively determines C. 3NF eliminates these dependencies.

Why is 3NF Important?

Adhering to 3NF offers several benefits:

  • Reduced Data Redundancy: Eliminating transitive dependencies reduces the amount of duplicate data stored in the database.
  • Improved Data Integrity: Changes to data only need to be made in one place, reducing the risk of inconsistencies.
  • Easier Data Modification: Updates, insertions, and deletions are simpler and less prone to errors.
  • More Flexible Database Design: 3NF allows for more flexible and adaptable database schemas.

How to Determine if a Table is in 3NF

To determine if a table is in 3NF, you need to:

  1. Identify the primary key of the table.
  2. Identify all non-key attributes.
  3. Check if any non-key attribute depends on another non-key attribute.
  4. If a non-key attribute depends on another non-key attribute, the table is not in 3NF.

Example

Consider the following table:

EmployeeID EmployeeName DepartmentID DepartmentName
1 Alice 10 Sales
2 Bob 20 Marketing

In this table:

  • Primary Key: EmployeeID
  • Non-Key Attributes: EmployeeName, DepartmentID, DepartmentName

Here, DepartmentName is dependent on DepartmentID, which is a non-key attribute. Therefore, there is a transitive dependency (EmployeeID -> DepartmentID -> DepartmentName). This table is not in 3NF.

To achieve 3NF, we would decompose this table into two tables:

EmployeeID EmployeeName DepartmentID
1 Alice 10
2 Bob 20
DepartmentID DepartmentName
10 Sales
20 Marketing

Now, each table is in 3NF. The `DepartmentName` is directly dependent on `DepartmentID` in the `Departments` table, and there are no transitive dependencies.

Summary

3NF is a crucial normal form in database design that helps to eliminate data redundancy and improve data integrity. By ensuring that non-key attributes are not transitively dependent on the primary key, we can create more robust and efficient database schemas.