Database Management System · Unit 7 · 7 hrs
Relational Database Design
Exam-focused notes for Relational Database Design (Database Management System, CSC265): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.
Relational Database Design in short
This unit turns an ER diagram into a set of relational tables, lays out informal design guidelines for spotting a poor schema, and then formalizes "poor schema" precisely through functional dependencies and the normal forms (1NF through 4NF), the part of the syllabus where marks are lost or won on rigor.
What this unit covers
- Relational Database Design Using ER-to-Relational Mapping
- Informal Design Guidelines for Relational Schemas
- Functional Dependencies
- Normal Forms Based on Primary Keys
- General Definitions of Second and Third Normal Forms
- Boyce-Codd Normal Form
- Multivalued Dependency and Fourth Normal Form
- Properties of Relational Decomposition
Normal Forms Based on Primary Keys
2080 · 10 marks
Define normalization. Why normalization is important in database design? Explain 1NF, 2NF and 3NF with suitable example.[10]
Show solved answerHide answer
Normalization in Database Design
Definition of Normalization
Normalization is the process of organizing the attributes and tables of a relational database to minimize data redundancy and dependency. It involves decomposing a large, poorly structured table into smaller, well-structured tables while preserving data integrity and relationships. The process is guided by a series of rules called Normal Forms (NF).
Why Normalization is Important in Database Design
Normalization is important for the following reasons:
| Reason | Explanation |
|---|---|
| Eliminates Redundancy | Avoids storing the same data in multiple places, saving storage space |
| Prevents Update Anomalies | Ensures that updating one record does not require updating many records |
| Prevents Insertion Anomalies | Allows inserting data without requiring unrelated data to be present |
| Prevents Deletion Anomalies | Prevents accidental loss of useful data when deleting a record |
| Improves Data Integrity | Maintains consistency and accuracy of data across the database |
| Simplifies Queries | Well-structured tables make querying easier and more efficient |
Types of Anomalies (Before Normalization)
Consider the following unnormalized table:
| StudentID | StudentName | CourseID | CourseName | InstructorName |
|---|---|---|---|---|
| 1 | Ram | C01 | DBMS | Dr. Sharma |
| 1 | Ram | C02 | OS | Dr. Thapa |
| 2 | Sita | C01 | DBMS | Dr. Sharma |
- Update Anomaly: If Dr. Sharma's name changes, it must be updated in multiple rows.
- Insertion Anomaly: A new course cannot be added without a student.
- Deletion Anomaly: Deleting Sita's record also deletes information about Course C01.
Normal Forms
1. First Normal Form (1NF)
Definition: A relation is in 1NF if:
- All attributes contain only atomic (indivisible) values.
- Each column contains values of a single type.
- Each row is unique (has a primary key).
- There are no repeating groups or multi-valued attributes.
Example of a table NOT in 1NF:
| StudentID | StudentName | Courses |
|---|---|---|
| 1 | Ram | DBMS, OS |
| 2 | Sita | DBMS |
Here, the Courses column contains multiple values, which violates 1NF.
Converting to 1NF:
| StudentID | StudentName | Course |
|---|---|---|
| 1 | Ram | DBMS |
| 1 | Ram | OS |
| 2 | Sita | DBMS |
Now each cell has an atomic value. This table is in 1NF. Primary Key: (StudentID, Course)
2. Second Normal Form (2NF)
Definition: A relation is in 2NF if:
- It is already in 1NF.
- Every non-key attribute is fully functionally dependent on the entire primary key (no partial dependency).
Partial Dependency: A non-key attribute depends on only a part of a composite primary key.
Example of a table in 1NF but NOT in 2NF:
| StudentID | Course | StudentName | InstructorName |
|---|---|---|---|
| 1 | DBMS | Ram | Dr. Sharma |
| 1 | OS | Ram | Dr. Thapa |
| 2 | DBMS | Sita | Dr. Sharma |
Primary Key: (StudentID, Course)
Functional Dependencies:
- (StudentID, Course) --> InstructorName (full dependency - OK)
- StudentID --> StudentName (partial dependency - VIOLATION)
StudentName depends only on StudentID, not on the full composite key.
Converting to 2NF (Remove partial dependencies):
Student Table:
| StudentID | StudentName |
|---|---|
| 1 | Ram |
| 2 | Sita |
Enrollment Table:
| StudentID | Course | InstructorName |
|---|---|---|
| 1 | DBMS | Dr. Sharma |
| 1 | OS | Dr. Thapa |
| 2 | DBMS | Dr. Sharma |
Now all non-key attributes are fully dependent on the primary key. Both tables are in 2NF.
3. Third Normal Form (3NF)
Definition: A relation is in 3NF if:
- It is already in 2NF.
- There is no transitive dependency of non-key attributes on the primary key.
Transitive Dependency: A non-key attribute depends on another non-key attribute, which in turn depends on the primary key. If A --> B and B --> C, then A --> C is a transitive dependency.
Example of a table in 2NF but NOT in 3NF:
| StudentID | Course | InstructorID | InstructorName |
|---|---|---|---|
| 1 | DBMS | I01 | Dr. Sharma |
| 1 | OS | I02 | Dr. Thapa |
| 2 | DBMS | I01 | Dr. Sharma |
Primary Key: (StudentID, Course)
Functional Dependencies:
- (StudentID, Course) --> InstructorID (full dependency - OK)
- InstructorID --> InstructorName (transitive dependency - VIOLATION)
Here: (StudentID, Course) --> InstructorID --> InstructorName
InstructorName depends on InstructorID (a non-key attribute), not directly on the primary key.
Converting to 3NF (Remove transitive dependencies):
Enrollment Table:
| StudentID | Course | InstructorID |
|---|---|---|
| 1 | DBMS | I01 |
| 1 | OS | I02 |
| 2 | DBMS | I01 |
Instructor Table:
| InstructorID | InstructorName |
|---|---|
| I01 | Dr. Sharma |
| I02 | Dr. Thapa |
The transitive dependency is now gone. InstructorName is stored exactly once, in the table whose key it actually depends on, while the Enrollment table keeps only InstructorID as a foreign key. Both tables are in 3NF, and the original information can be recovered without loss by joining them on InstructorID.
The anomalies listed at the beginning disappear with it. Correcting Dr. Sharma's name now changes a single row of the Instructor table, so there is no update anomaly. A new instructor can be recorded before any student enrols under that instructor, so there is no insertion anomaly. Deleting the last enrolment for a course no longer erases the instructor's details, so there is no deletion anomaly.
Summary of the Three Normal Forms
| Normal Form | Requirement | Problem Removed |
|---|---|---|
| 1NF | All attribute values atomic, no repeating groups | Multi valued cells that cannot be queried or indexed |
| 2NF | In 1NF and every non key attribute fully dependent on the whole primary key | Redundancy caused by partial dependency on part of a composite key |
| 3NF | In 2NF and no transitive dependency on the primary key | Redundancy caused by one non key attribute determining another |
Normalization therefore moves a design from a single wide table full of repeated facts towards a set of narrow tables in which every fact is stored once and depends on the key, the whole key and nothing but the key. Stricter forms such as BCNF and 4NF handle the remaining special cases, but 3NF is normally sufficient for practical database design, and a controlled amount of denormalization is added afterwards only where read performance demands it.
2076 · 10 marks
What is normal form? Explain their types. Explain about loss-less join decomposition.[10]
General Definitions of Second and Third Normal Forms
2079 · 10 marks
What is normalization? Why normalization is required? Explain 1NF, 2NF, and 3NF with example.[10]
Functional Dependencies
2079 · 5 marks
Define functional dependencies. Explain 2nd normal form with example. [5]
Show solved answerHide answer
Functional Dependencies and Second Normal Form (2NF)
Functional Dependency (FD)
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.
- 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:
- The relation must be in 1NF
- 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:
| StudentID | CourseID | StudentName | CourseName | Grade |
|---|---|---|---|---|
| S01 | C01 | Ram | DBMS | A |
| S01 | C02 | Ram | OS | B |
| S02 | C01 | Sita | DBMS | A+ |
- 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
| StudentID | StudentName |
|---|---|
| S01 | Ram |
| S02 | Sita |
Table 2: Course
| CourseID | CourseName |
|---|---|
| C01 | DBMS |
| C02 | OS |
Table 3: Enrollment
| StudentID | CourseID | Grade |
|---|---|---|
| S01 | C01 | A |
| S01 | C02 | B |
| S02 | C01 | A+ |
Now every non-prime attribute is fully dependent on the entire primary key. All three tables are in 2NF.
Summary
| Concept | Description |
|---|---|
| 1NF required | Yes |
| Partial dependency | Not allowed |
| Full dependency | Every non-prime attribute depends on the whole candidate key |
2078 · 5 marks
Define Functional dependencies. Explain trivial and non trivial dependencies? [5]
Boyce-Codd Normal Form
2078 · 5 marks
Define Boyce-Codd normal form with example. How it is different that 3rd Normal form. [5]
Informal Design Guidelines for Relational Schemas
2080.1 · 10 marks
What are informal design guidelines for relational schemas? why do we need functional dependencies? Explain 2NF, 3NF with suitable example.[10]
Make Unit 7 stick
Practice CSC265 with flashcards & quizzes