Database.Explain 2nf, give example

📗 Second Normal Form (2NF)

2NF (Second Normal Form) builds on 1NF and adds one more rule:

A table is in 2NF if:

  1. It is in 1NF, and
  2. All non-key attributes are fully functionally dependent on the entire primary key.

🔍 What Does “Fully Dependent” Mean?

If the primary key is composite (made of two or more columns), then:

  • A non-key column must depend on both parts of the key, not just one.

❌ Example: Not in 2NF

Table: StudentCourses

StudentIDCourseIDStudentNameCourseName
1CS101AliceJava
1CS102AliceSQL
2CS101BobJava
  • Composite Primary Key: (StudentID, CourseID)
  • Problem:
    • StudentName depends only on StudentID
    • CourseName depends only on CourseID

❌ These are partial dependencies, so this table is not in 2NF.


✅ Convert to 2NF: Split into Two Tables

Table: Students

StudentIDStudentName
1Alice
2Bob

Table: Courses

CourseIDCourseName
CS101Java
CS102SQL

Table: StudentCourses

StudentIDCourseID
1CS101
1CS102
2CS101
  • ✅ Now, all non-key attributes fully depend on their entire primary key.
  • ✅ This structure is in 2NF.

💡 Summary:

Normal FormKey Rule
1NFAtomic values, no repeating groups
2NFNo partial dependency on a composite key
This entry was posted in Без рубрики. Bookmark the permalink.