Dbms Mid-2 Unit-4 Longs Answers
Dbms Mid-2 Unit-4 Longs Answers
Summary:
AG is a candidate key.
A⁺ = {A, B, C, H}
CG⁺ = {C, G, H, I}
AG⁺ = {A, B, C, G, H, I} = all attributes
Formal Condition:
A relation R is in 4NF if, for every non-trivial multi-valued
dependency X↠YX \twoheadrightarrow YX↠Y in R, X is a
superkey.
Example:
Suppose a university records the following information:
A Student can enroll in multiple Courses.
A Student can have multiple Hobbies.
Relation:
Student_Info(Student_ID,Course,Hobby)
Data:
Student_ID Course Hobby
1 Math Painting
1 Science Painting
1 Math Chess
1 Science Chess
Student 1 is enrolled in both Math and Science.
Student 1 has hobbies Painting and Chess.
Notice:
Courses and Hobbies are independent of each other for
the same student.
Thus, there are multi-valued dependencies:
o Student_ID↠CourseStudent
o Student_ID↠HobbyStudent
This violates 4NF.
Solution (Decomposition):
We split into two relations:
1. Student_Course(Student_ID,Course)
Student_ID Course
1 Math
1 Science
2. Student_Hobby(Student_ID,Hobby)Student\
_Hobby(Student\_ID,
Hobby)Student_Hobby(Student_ID,Hobby)
Student_ID Hobby
1 Painting
1 Chess
Now:
No multi-valued dependencies exist in either table.
Both tables are in 4NF.
🔥 Final Points:
4NF removes unwanted multi-valued dependencies.
Decomposition results in lossless and dependency-
preserving relations.
It is stricter than BCNF.
Formal Condition:
A decomposition of relation RRR into R1R_1R1 and
R2R_2R2 is lossless if at least one of these conditions
holds:
(R1∩R2)→R1
(R1∩R2)→R2
That means the common attributes between R1R_1R1 and
R2R_2R2 must uniquely identify either R1 or R2
Example:
Suppose we have a relation:
Student(Student_ID,Name,Course)Student(Student\_ID,
Name, Course)Student(Student_ID,Name,Course)
We decompose it into:
R1(Student_ID,Name)
R2(Student_ID,Course)
Here:
Common attribute = Student_IDStudent\_IDStudent_ID
Student_ID → Name (from original FD)
Student_ID → Course (from original FD)
Student_ID uniquely identifies both parts, the join will
reconstruct the original Student table without loss.
Thus, this decomposition is lossless.
Quick Diagram:
Original Relation → Decompose → Sub-relations → Join →
Get back Original Relation
✅ (If Lossless)
❌ (If Lossy — wrong or incomplete data)
🔥 Final Points:
Lossless decomposition preserves data perfectly.
Common attribute must be a key for at least one sub-
relation.
It is critical for database normalization.
Formal Condition:
A relation is in 3NF if, for every functional dependency
X→YX \to YX→Y:
X→Y is a trivial dependency (Y ⊆ X), OR
X Is a superkey, OR
Each attribute in Y is a prime attribute (part of some
candidate key).
Example:
Consider a relation:
Employee(Emp_ID,Emp_Name,Dept_ID,Dept_Name)
Functional Dependencies:
Emp_ID→Emp_Name,Dept_ID
Dept_ID→Dept_Name
Primary Key: Emp_ID
Problem:
Emp_ID → Dept_ID (fine, direct dependency)
Dept_ID → Dept_Name (Dept_Name depends on
Dept_ID, not directly on Emp_ID → transitive
dependency)
Thus, this relation is NOT in 3NF.
Solution (Decomposition):
Split into two relations:
1. Employee(Emp_ID,Emp_Name,Dept_ID)
2. Department(Dept_ID,Dept_Name)
Now:
In Employee, every non-prime attribute (Emp_Name,
Dept_ID) depends only on Emp_ID.
In Department, Dept_Name depends only on Dept_ID.
Thus, both are in 3NF!
🔥 Final Points:
3NF removes transitive dependency.
It preserves functional dependencies.
3NF is a balance between good normalization and good
performance.
5. Define BCNF. How does BCNF differ from 3NF? Explain
with an example
5A) Definition:
A relation is in Boyce-Codd Normal Form (BCNF) if, for
every non-trivial functional dependency X→YX \to YX→Y,
XXX must be a superkey.
In short:
In BCNF, left-hand side of every functional dependency
must be a superkey.
Check 3NF:
(Student_ID, Course_Code) → Instructor (Fine — LHS is a
superkey)
Instructor → Course_Code
o Instructor is not a superkey.
o But Course_Code is a prime attribute (part of the
candidate key).
Thus, satisfies 3NF.
Check BCNF:
Instructor → Course_Code
o Instructor is not a superkey. Thus, NOT in BCNF.
Solution (Decomposition):
Split R into two relations:
1. R1(Instructor,Course_Code)
2. R2(Student_ID,Instructor)
Now:
In R1, Instructor → Course_Code (Instructor is key here)
In R2, Student_ID + Instructor can determine
Course_Code if needed
Thus, both relations are now in BCNF!
🔥 Final Points:
BCNF removes all redundancy caused by functional
dependencies.
BCNF demands stronger normalization than 3NF.
In BCNF, every dependency must start from a superkey.
6. Transitive Dependency
When A→B and B→C imply A→C
B is an intermediate dependency.
Example:
Emp_ID→Dept_ID
Thus, Emp_ID→Dept_Name (transitive).
🔥 Final Points:
Functional dependencies help to normalize the
database.
They remove redundancy and maintain data integrity.
They are the backbone for 2NF, 3NF, BCNF, and beyond.
Example:
Suppose we have a relation:
Student_ID Name Subjects
1 Varun Math, Physics
2 Akash Chemistry
Problem: In the "Subjects" column, multiple subjects are
stored together (not atomic).
Thus, NOT in 1NF.
Convert to 1NF:
We split multiple values into separate rows:
Student_ID Name Subject
1 Varun Math
1 Varun Physics
2 Akash Chemistry
✅ Now:
Each field contains only one value.
The table follows 1NF.
🔥 Final Points:
Surrogate Keys are system-generated unique identifiers.
They have no business meaning.
They are useful for stability and performance in large
databases.
Key Terms:
Prime Attribute: Attribute that is part of a candidate key.
Partial Dependency: When an attribute depends only on
part of a composite primary key.
Example:
Suppose we have a relation:
Student_I Course_Cod Instructor_Nam Departmen
D e e t
1 CS101 Dr. Smith CS
2 MA101 Dr. John Math
Functional Dependencies:
(Student_ID, Course_Code) → Instructor_Name
Course_Code → Department
Primary Key: (Student_ID, Course_Code)
Problem:
Department depends only on Course_Code (a part of
the composite key).
This is a partial dependency, so the relation is NOT in
2NF.
🔥 Final Points:
2NF = 1NF + no partial dependency.
Non-prime attributes must depend on the entire key.
Helps to make databases more consistent and efficient.
Key Points:
MVDs deal with sets of values, not single values.
They typically occur when two attributes are
independent but depend on the same key.
MVDs are crucial for achieving Fourth Normal Form
(4NF).
Example:
Consider a table storing information about students, their
hobbies, and their languages:
Student_ID Hobby Language
1 Painting English
1 Painting Hindi
1 Dancing English
1 Dancing Hindi
Here:
A student can have multiple hobbies.
A student can speak multiple languages.
But hobbies and languages are independent of each
other.
Thus:
Student_ID↠Hobby
Student_ID↠Language
✅ It is a multivalued dependency.
Important:
If a relation has a non-trivial MVD, it can lead to
unnecessary repetition.
Hence, we decompose the relation into two tables:
1. Student_Hobby(Student_ID,Hobby)
2. Student_Language(Student_ID,Language)
✅ Now, no redundancy and the design is ready for Fourth
Normal Form (4NF).
🔥 Final Points:
MVD represents multiple independent values related to
a single attribute.
It causes repetition if not handled properly.
It is removed by 4NF decomposition.
11. Explain about dependency preserving
decomposition with an example
11A) Definition:
A dependency-preserving decomposition is one where all
the functional dependencies (FDs) that hold in the original
relation are also preserved in the decomposed relations. This
means that after decomposition, we can still enforce all the
original FDs without needing to join the decomposed tables.
In simple words:
A decomposition is dependency-preserving if the original
constraints can be recovered by looking at the decomposed
tables individually (without needing joins).
Key Characteristics:
Preserves FDs: All original functional dependencies are
represented in the decomposed schema.
No Need for Joins: You can enforce all original FDs
without needing to perform a join between the
decomposed relations.
Reduces Redundancy: Decomposition helps eliminate
redundancy and update anomalies.
Example:
Consider a relation R(A,B,C,D)with the following functional
dependencies:
1. A→B
2. C→D
3. A,C→D
Step 1: Decompose the Relation
We decompose R(A,B,C,D) into two relations:
1. R1(A,B)
2. R2(C,D)
Now, let's check if the decomposition is dependency-
preserving:
Original FDs:
o A→B→ Preserved in R1(A,B)
o C→D → Preserved in R2(C,D)
o A,C→D C→D → Not directly preserved, but we can
see that A→B in the decomposed relations enforce
the FD.
In this case, all the functional dependencies are preserved
without requiring a join, so the decomposition is
dependency-preserving.
🔥 Final Points:
Dependency-Preserving means all FDs in the original
relation are maintained in the decomposed tables.
It ensures data consistency and validity without extra
complexity (like joins).
If FDs are not preserved, the integrity constraints could
break down, requiring additional work.