CSC265 Database Management System

Database Management SystemUnit 710 min read

Unit 7: Relational Database Design & Normalization

Unit 7 of Database Management System: covers functional dependencies, inference rules, loss-less join and dependency preservation, and normal forms up to BCNF for relational database design.

Key points

  • Database design aims to minimize data redundancy and prevent update anomalies using formal decomposition methods.
  • Functional dependencies (FDs) are integrity constraints that specify relationships between attributes in a relation.
  • Normalization progresses relations through 1NF, 2NF, 3NF, and BCNF to progressively eliminate anomalies.
  • Lossless-join and dependency-preservation properties ensure that decomposed schemas retain all original information and functional constraints.
  • Boyce-Codd Normal Form (BCNF) is a stricter version of 3NF where every determinant must be a candidate key.

Introduction to Relational Database Design

The primary objective of relational database design is to group attributes into relations to minimize data redundancy and manage update, insertion, and deletion anomalies. Poorly designed databases often suffer from redundancy, which wastes storage space and leads to inconsistent data states.

Anomalies Caused by Redundancy

When a relation contains redundant data, three major anomalies occur:

  1. Insertion Anomaly: Inability to insert certain data without introducing dummy or null values in unrelated attributes. For example, if a department's details are stored only alongside employee records, a new department cannot be added until at least one employee is assigned to it.
  2. Deletion Anomaly: Unintentional loss of information due to the deletion of other data. For instance, deleting the last employee in a department deletes all details about that department.
  3. Modification (Update) Anomaly: Changing data in one place but missing it in another, resulting in database inconsistency. For example, changing an employee's address in one row but leaving it unchanged in another row for the same department/employee combination.

Functional Dependencies (FDs)

A Functional Dependency is a constraint between two sets of attributes in a relation from a database. Let be a relation schema, and let and be subsets of the attributes of . A functional dependency, denoted by (read as " functionally determines "), specifies that for any two tuples and in any legal instance of :

This means the values of the component uniquely determine the values of the component.

Inference Rules for Functional Dependencies (Armstrong's Axioms)

Let be the universal set of attributes. Armstrong's axioms are a sound and complete set of inference rules used to infer all functional dependencies that are logically implied by a given set of functional dependencies :

  1. Reflexivity: If , then .
  2. Augmentation: If , then for any set of attributes .
  3. Transitivity: If and , then .

Using these three axioms, additional useful rules can be derived:

  • Union: If and , then .
  • Decomposition: If , then and .
  • Pseudo-transitivity: If and , then .

Closure of a Set of Functional Dependencies ()

The set of all functional dependencies that can be logically derived from a given set using Armstrong's axioms is called the closure of , denoted as .

Closure of a Set of Attributes ()

Given a set of attributes and a set of functional dependencies , the attribute closure of under (denoted as ) is the set of all attributes that can be functionally determined by .

Algorithm to find :

  1. Set .
  2. Repeat until no more attributes can be added:
    • For each functional dependency in :
      • If , then set .

Example: Consider relation with functional dependency set . Let us find the closure of attribute set :

  • Initial:
  • Using :
  • Using :
  • Using :
  • Using :
  • Using : $E^+ =
  • Using (since ):

Since contains all attributes of , is a candidate key for .


Decomposition of Relation Schemas

When a relation schema suffers from anomalies, it is broken down into a set of smaller relations in a process called decomposition.

Desirable Properties of Decomposition

  1. Lossless-Join Property: When relations in the decomposition are joined back together using natural joins, the original relation must be perfectly reconstructed without generating any spurious (extra, incorrect) tuples.
  2. Dependency Preservation Property: Every functional dependency in the original set must be represented in at least one of the decomposed relations, or be derivable from the dependencies in the decomposed schemas.

Normalization

Normalization is the formal, step-by-step process of analyzing relational schemas based on their functional dependencies and primary keys to minimize redundancy and anomalies.

+-------------------------------------------------------+
| Unnormalized Form (UNF)                               |
+-------------------------------------------------------+
                           |
                           v
+-------------------------------------------------------+
| First Normal Form (1NF) - Atomic values               |
+-------------------------------------------------------+
                           |
                           v
+-------------------------------------------------------+
| Second Normal Form (2NF) - No partial dependency      |
+-------------------------------------------------------+
                           |
                           v
+-------------------------------------------------------+
| Third Normal Form (3NF) - No transitive dependency    |
+-------------------------------------------------------+
                           |
                           v
+-------------------------------------------------------+
| Boyce-Codd Normal Form (BCNF) - Every LHS is a key    |
+-------------------------------------------------------+

First Normal Form (1NF)

A relation is in 1NF if the domain of each attribute contains only atomic (indivisible) values, and the value in each cell of a relation is a single scalar value (no multi-valued or composite attributes).

Second Normal Form (2NF)

A relation is in 2NF if:

  1. It is in 1NF.
  2. Every non-prime attribute (an attribute not part of any candidate key) is fully functionally dependent on the primary key. This means there must be no partial dependency (no non-prime attribute depends on a proper subset of a composite candidate key).

Example: Consider relation .

  • Primary Key:
  • Partial Dependencies:
    • (StudentName depends only on part of the key)
    • (CourseName depends only on part of the key)
  • Decomposition into 2NF:

Third Normal Form (3NF)

A relation is in 3NF if:

  1. It is in 2NF.
  2. There is no transitive dependency for non-prime attributes. That is, for every non-trivial functional dependency , at least one of the following conditions holds:
    • is a super key of the relation, OR
    • is a prime attribute (each attribute in is part of some candidate key).

Example: Consider relation .

  • Primary Key:
  • Functional Dependencies:
    • (Transitive dependency: )
  • Decomposition into 3NF:

Boyce-Codd Normal Form (BCNF)

A relation is in BCNF if it is stricter than 3NF. A relation is in BCNF if for every non-trivial functional dependency , must be a super key of .

Every relation in BCNF is also in 3NF, but not every relation in 3NF is in BCNF. A 3NF relation fails BCNF if a prime attribute depends on a non-prime attribute, or if a non-prime attribute determines another non-prime attribute.

Example: Consider relation where a course can have multiple instructors, but a specific instructor teaches only one course.

  • Candidate Keys: and
  • Functional Dependencies:
  • Here, is a dependency where the left-hand side () is not a super key. Thus, is not in BCNF.
  • Decomposition into BCNF:

Comparison of Normal Forms

Normal Form Primary Condition Eliminates Anomalies Caused By
1NF Atomic attribute values only Multi-valued and composite attributes
2NF 1NF + No partial dependencies on candidate keys Partial functional dependencies
3NF 2NF + No transitive dependencies of non-prime attributes Transitive dependencies
BCNF Every determinant is a super key Overlapping candidate keys and hidden dependencies

Exam Tip

Tribhuvan University (TU) board exams frequently test this unit with a numerical problem where you are given a relation with a set of functional dependencies, and asked to:

  1. Find candidate keys using attribute closure.
  2. Determine the highest normal form the relation satisfies.
  3. Decompose the relation into 3NF or BCNF while checking for lossless-join and dependency preservation properties. Practice at least 5 numerical problems from past questions, as these carry full 8 to 10 marks.

Based on the TU BSc CSIT syllabus for Database Management System (CSC265), unit 7.

Discussion

Loading…