2079 8

CSC265 ยท 2079 ยท 5 marks

Define functional dependencies. Explain 2nd normal form with example.

Define functional dependencies. Explain 2nd normal form with example. [5]

Database Management SystemChapter 7: Relational Database DesignFunctional Dependencies

Quick answer

A functional dependency is a constraint between two sets of attributes in a relation. For a relation R, a functional dependency X โ†’ Y means that the value of attribute set X uniquely determines the value of attribute set Y.

Functional Dependencies and Second Normal Form (2NF)


Functional Dependency (FD)

  • X is called the determinant
  • Y is called the dependent

Example: In a Student table, StudentID โ†’ StudentName means that knowing the StudentID uniquely determines the StudentName.

A set of functional dependencies is given for each relation, and each relation has a designated primary key, which is then evaluated for normalization. (from notes)


Second Normal Form (2NF)

"To be in second normal form, a relation must be in First Normal Form AND the relation must not contain any partial dependency." (from notes)

Key Definitions:

  • Non-prime attribute: An attribute that is not part of any candidate key
  • Partial Dependency: When a proper subset of a candidate key determines a non-prime attribute
Partial Dependency = Proper subset of candidate key โ†’ non-prime attribute

Conditions for 2NF:

  1. The relation must be in 1NF
  2. There must be no partial dependency (every non-prime attribute must be fully functionally dependent on the whole candidate key)

Example

Table NOT in 2NF:

StudentIDCourseIDStudentNameCourseNameGrade
S01C01RamDBMSA
S01C02RamOSB
S02C01SitaDBMSA+
  • Primary Key (Composite): {StudentID, CourseID}
  • Functional Dependencies:
    • StudentID, CourseID โ†’ Grade (full dependency - OK)
    • StudentID โ†’ StudentName (partial dependency - violation)
    • CourseID โ†’ CourseName (partial dependency - violation)

Since StudentName depends only on StudentID (a proper subset of the composite key), this is a partial dependency, so the table is NOT in 2NF.


Decomposition to achieve 2NF:

Table 1: Student

StudentIDStudentName
S01Ram
S02Sita

Table 2: Course

CourseIDCourseName
C01DBMS
C02OS

Table 3: Enrollment

StudentIDCourseIDGrade
S01C01A
S01C02B
S02C01A+

Now every non-prime attribute is fully dependent on the entire primary key. All three tables are in 2NF.


Summary

ConceptDescription
1NF requiredYes
Partial dependencyNot allowed
Full dependencyEvery non-prime attribute depends on the whole candidate key

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.