DBMS Normalization Examples and Analysis
DBMS Normalization Examples and Analysis
1. Student database (attributes: sid, sname, sex, major, gpa, activity, fee)
Below I give concrete table instances, explanation which normal form they violate, and the
decomposition to the next normal form. I state keys and constraints for each result.
StudentBad(
Why not 1NF: the activity field contains multiple values (comma separated). 1NF requires
atomic values.
Fix to 1NF: split multi-valued attributes into separate rows (one row per activity) or create a
separate activity relation.
We need a relation that is 1NF and has a composite primary key with partial dependency (some
non-key attribute depends on part of the composite key).
Relation (1NF):
StudentActivity(
Primary key: (sid, activity) — each student can have many activities.
• sname, sex, major, gpa, fee depend only on sid (part of the composite key) — not on the
whole key (sid, activity). So partial dependency exists ⇒ not 2NF.
Convert to 2NF (remove partial dependencies):
Decompose into:
Constraints:
To violate 3NF while in 2NF we need a transitive dependency: a non-key attribute depends on
another non-key attribute (A → B where A is non-key and B is non-key).
Start from STUDENT(sid, sname, sex, major, gpa, fee). Add an attribute that depends on major (a
non-key attribute): e.g. dept_name.
• But sid → major and major → dept_name produce a transitive dependency sid →
dept_name via major. dept_name is a non-prime attribute dependent on another non-
prime attribute (major) — violates 3NF.
Convert to 3NF:
Decompose into:
Constraints:
A typical textbook pattern for 3NF but not BCNF uses an FD whose left side is not a superkey but
whose right side is a prime attribute (part of some candidate key).
Suppose:
• Suppose the policy: activity → fee (each activity has a fixed participation fee).
• Suppose for some reason there is a candidate key that includes fee (e.g., unusual model
where (sid, fee) together can be a candidate key in some contrived design — but to keep
it realistic: we can show a standard textbook example instead).
However, making a realistic student example that is 3NF but not BCNF can be confusing in
natural student schemas. So here I give the standard canonical example (adapt it to student
domain):
• fee → organizer (each fee amount is associated with a particular organizer) — contrived
but possible if only one organizer charges a specific fixed fee
Assume candidate keys are {activity, organizer} (or some keys where fee participates in a key) so
that fee is a prime attribute. Then:
• But if fee is prime (part of some candidate key), 3NF allows it. So the relation can be in
3NF but not BCNF.
1. R1(activity, fee)
2. R2(activity, organizer)
(If you want a strictly student-domain, fully realistic 3NF-but-not-BCNF example, I can produce
one with a clear candidate-key calculation — tell me and I'll make it explicit.)
V. Why higher normal forms (4NF, 5NF, DKNF)? Which is the highest?
• 5NF (Project-Join Normal Form / PJNF): addresses cases where a relation must be split
to avoid redundancy due to join dependencies that are not expressible as FDs. It
ensures every join dependency in the relation is implied by candidate keys.
• Domain/Key Normal Form (DKNF): the strongest (conceptual) normal form: every
constraint on the relation is a logical consequence of domain constraints and key
constraints. In practice DKNF is rare and often unnecessary.
Highest normal form in theory: Domain/Key Normal Form (DKNF) is the strongest. In practice
BCNF/4NF/5NF are more commonly considered; DKNF is more of a theoretical ideal.
• Closure of M:
From M → Mp, M gives Mp. From Mp → C, M gives C. So M⁺ = {M, Mp, C}. It does not
include Y or P. So M is not a key.
• Closure of MY:
From M → Mp, MY gives Mp. From Mp → C, we get C. From MY → P, with M and Y present
we get P. So MY⁺ = {M, Y, Mp, C, P} — all attributes. So MY is a candidate key. It's
minimal because neither M alone nor Y alone is a key, so MY is minimal.
• Closure of MC:
MC contains M and C. From M → Mp you get Mp, from Mp → C gives C (already present).
You still do not get Y or P (MY → P needs Y). So MC⁺ = {M, Mp, C}. Not all attributes ⇒ MC
is not a key.
We check every FD X → A in F:
F contains:
1. M → Mp
2. MY → P
3. Mp → C
Candidate key(s): we found {M,Y} is a candidate key. So the prime attributes are M and Y
(attributes that appear in some candidate key).
3NF condition for each FD X → A:
• either X is a superkey, OR
Check each:
1. M → Mp: LHS M is not a superkey (M⁺ ≠ all). RHS Mp is not prime (Mp is not in any
candidate key). ⇒ violates 3NF.
• Intersection: R1 ∩ R2 = {M}.
• Check whether (R1 ∩ R2) → R1 or → R2 using the original F (or its closure).
When the intersection {M} functionally determines all attributes of one of the decomposed
relations (here R2), the decomposition is lossless.
We must check whether every FD in the original set F can be checked (enforced) using the FDs
that hold on the decomposed relations (i.e., projections of F onto R1 and R2) without doing a
join.
Project F onto R1(M,Y,P):
• From original F, the only FD projected onto R1 is MY → P (since it uses only M,Y,P).
• From original F, the FDs whose attributes are subset of R2 are: M → Mp and Mp → C.
• M → Mp: in R2
• Mp → C: in R2
• MY → P: in R1
Q3 — Relation
R = (A B C D E F G)
F = { AB → CD, AF → D, DE → F, C → G, F → E, G → A }
First note which attributes appear on RHS of some FD: {C, D, F, G, E, A}.
The only attribute not on any RHS is B, so B must appear in every key.
• {A, B, F}:
o AB → C,D ⇒ add C, D
o C → G ⇒ add G
o G → A ⇒ A already present
o F → E ⇒ add E
• {B, C, F}:
o C → G ⇒ add G
o G → A ⇒ add A
o F → E ⇒ add E
=> closure = all attributes. Minimal (no subset closes), so {B,C,F} is a key.
• {B, G, F}:
o G → A ⇒ add A
o F → E ⇒ add E
=> closure = all attributes. Minimal as well. So {B,G,F} is a key.
You can check there are no smaller keys. So the candidate keys are:
{A, B, F}, {B, C, F}, {B, G, F}.
(ii) Apply closure algorithm and find closure of F (interpretation & useful attribute
closures)
• B⁺ = {B}
• C⁺ = {C, G, A}
• D⁺ = {D}
• E⁺ = {E}
• F⁺ = {F, E} (by F → E)
• G⁺ = {G, A}
• AB⁺ = {A,B,C,D,G}
• AF⁺ = {A,F,D,E}
• CF⁺ = {A,C,D,E,F,G}
Start with F:
1. AB → C D → split to AB → C and AB → D
2. AF → D
3. DE → F
4. C → G
5. F → E
6. G → A
• All LHS sides are already minimal (no single attribute can be removed without losing the
FD).
• None of the FDs is implied by the others (test removing each one and computing
closures shows they are necessary).
Gc = { AB → C, AB → D, AF → D, DE → F, C → G, F → E, G → A }
(You may present them grouped: AB→C,D; AF→D; DE→F; C→G; F→E; G→A.)
We have AB → D and AF → D. Both AB and AF are proper subsets of the candidate key {A,B,F}
and they determine D (a non-prime attribute). That is a partial dependency, so R is NOT in
2NF.
Convert to 2NF (one correct decomposition): remove relations that express partial
dependencies so that non-prime attributes are not partially dependent on part of a key. One
reasonable 2NF decomposition (lossless, dependency-preserving for this case) is:
(You can also include R4(G,A) for G→A if you want to keep that FD separately, but R3 plus
R1/R2 allow derivation of G and A as needed.)
This decomposition eliminates the partial dependency problem because in each relation
the determinant is a key of that relation.
(v) Is R in 3NF / BCNF? If not convert (and provide relations, check lossless /
dependency preserving)
Check 3NF for original R: 3NF requires for each nontrivial X→Y either:
• X is a superkey, or
Look at FDs:
• DE → F: DE not a superkey (DE⁺ not all) and F is prime (F is in all candidate keys) — since
F is prime this FD does not violate 3NF.
• C → G: C not superkey but G is prime (G appears in candidate key {B,G,F}) — OK for 3NF.
So because AB→D, AF→D, and F→E have non-prime RHS with non-superkey LHS, R is NOT in
3NF.
Canonical 3NF decomposition (algorithm via minimal cover): For each FD X→Y in
canonical cover make relation (X ∪ Y). Using our canonical cover, form relations:
Then ensure at least one relation contains a candidate key of R. Our candidate key {A,B,F} is
not contained in any single relation above, so add:
• Rkey( A, B, F )
{ R1(AB C), R2(AB D), R3(AF D), R4(DE F), R5(CG), R6(F E), R7(G A), Rkey(A B F) }
Properties:
• It can be shown to be lossless because the added Rkey relation contains a key of the
original R and the decomposition was built from the canonical cover.
BCNF check: In each of the relations above the FDs used to create them have left sides that
are keys for that relation (e.g., in R4, DE→F, DE is a key for R4; in R6, F→E F is key for R6; etc.).
So each of these component relations is in BCNF. Therefore the canonical decomposition
into those relation schemas yields relations that are BCNF. (The original R was not BCNF,
because it had FDs like M→Mp analogs where LHS is not a superkey.)
Q4 — Relation
R(A, B, C, D, E, F, G, H, I, J)
Functional dependencies:
FD = { AB → C, A → DE, B → F, F → GH, D → IJ }
Find attributes that never appear on RHS: scanning RHS values {C, D, E, F, G, H, I, J} — both
A and B do not appear on RHS. So both must be in any key. Compute AB⁺:
• From AB → C add C
• From A → DE add D, E
• From B → F add F
2NF: since AB is a composite key, check for partial dependencies (some non-prime attr
dependent on part of the key).
• A → D,E: A is part of key AB and D,E are non-prime (do not appear in any candidate key)
⇒ partial dependency ⇒ not 2NF.
So R is NOT in 2NF.
Decomposition to 2NF (example):
Separate the partial dependencies so that attributes dependent on a single part are in
separate relations:
• R1( A, D, E, I, J ) — because A → D,E and D → I,J. Here A is the key of R1. (D→IJ is kept
inside R1.)
(You can treat R1 and R2 as the 2NF components and R3 as the linking relation. This
decomposition is intuitive and commonly used in normalization exercises.)
• AB → C
• A→D
• A→E
• B→F
• F→G
• F→H
• D→I
• D→J
3NF decomposition (from canonical cover): create a relation for each FD of the canonical
cover:
We must ensure at least one relation contains a candidate key of the original relation; R5(
A,B,C ) contains AB so OK.
This decomposition:
• is dependency-preserving (every original FD appears in some relation),
• and by construction each relation has the FD determinant as a key of that relation. So
each component relation is in 3NF, and in fact each is in BCNF (because determinant is
key for that component).
Hence the above canonical 3NF decomposition is correct; you can also combine some
relations if you want (e.g. R1 and R4 could be merged into (A,D,E,I,J) because D→IJ is still
preserved there).
If by closure you mean calculate closures to check keys and implications: useful closures
are:
• B⁺ = {B, F, G, H} (B → F ; F → G,H)
• F⁺ = {F, G, H}
• D⁺ = {D, I, J}
If you want the full implied FD set F⁺ (all FDs implied by FD), it can be deduced from the
minimal cover above (every FD that can be computed from closures of LHS sets).
As computed:
A⁺ = { A, D, E, I, J }.
MODULE - 5
1. Break down the role of each ACID property and analyze the consequences of their
violation.
ACID stands for Atomicity, Consistency, Isolation, Durability. These properties ensure
reliable transaction processing.
1. Atomicity
o Inconsistent or corrupt data (e.g., money deducted from one account but not
credited to another).
2. Consistency
Consistency ensures that a transaction takes the database from one valid state to another
valid state, maintaining integrity constraints.
• Violation Consequence:
3. Isolation
Isolation ensures that concurrent transactions do not interfere with each other.
• Violation Consequence:
o Dirty reads
o Lost updates
o Non-repeatable reads
o Phantom reads
These lead to inconsistent query results.
4. Durability
Durability ensures that committed data is permanently saved, even if the system crashes.
• Violation Consequence:
Conclusion
2. Justify the need for serializability in concurrent transaction processing with real-life
consequences of ignoring it.
2. Lost Update – Two transactions modify the same data; one overwrites the other.
Example: Two people withdrawing money simultaneously; one withdrawal disappears.
3. Non-Repeatable Read – A transaction reads different values for the same item.
Example: E-commerce stock count changes mid-process.
Real-Life Consequences
Conclusion
3. Illustrate log-based recovery using undo and redo operations for a system crash
situation.
Log-based recovery records actions in a log file before applying them to the database
(Write-Ahead Logging – WAL).
Example Log
<T1 start>
<T2 start>
<T1 commit>
<System Crash>
• X = 30
• Y = 50
Steps in Recovery
Result
1. Recoverable Schedule
A schedule where a transaction commits only after the transaction from which it read data
has committed.
Example:
T2 reads X written by T1 → T2 commits after T1 commits.
2. Cascadeless Schedule
Example:
T2 reads X only after T1 commits.
Example:
T2 cannot read or write X until T1 commits/aborts.
Advantage:
• Easiest recovery
Hierarchy
Strict → Cascadeless → Recoverable
5. Differentiate between shadow paging and log-based recovery protocols and identify
scenarios best suited for each.
Shadow Paging
Advantages:
• No log storage
• Fast commit
Disadvantages:
• Page fragmentation
Best for:
Small databases, embedded systems, simple transactional workloads.
Log-Based Recovery
Advantages:
• Supports fine-grained recovery
• Supports checkpoints
Best for:
Commercial RDBMS (Oracle, MySQL), large-scale transaction systems.
• Network failures
• Site failures
• Message delays
• Coordinated commits
Why 2PC?
1. Site Crash:
2. Coordinator Failure:
3. Network Failure:
Conclusion
2PC combined with log-based recovery ensures reliable and synchronized recovery across
distributed nodes.
7. Design a transaction schedule that is recoverable but not cascadeless, and explain
the implications.
Schedule
T1: W(X)
T2: R(X)
T1: Commit
T2: Commit
Properties
• Recoverable:
T2 reads X from T1, and commits after T1 commits → OK.
• Not Cascadeless:
T2 read X before T1 commits → violates cascadeless rule.
Implications
8. Assess the pros and cons of using immediate update recovery methods in mission-
critical systems.
Immediate Update
Changes are written to the database before commit, but undo logs are maintained.
Pros
Cons
Suitability
Given:
Let:
• TS(T1) = 5
• TS(T2) = 10
Case Example:
T1: W(X)
T2: R(X)
Initially,
R-TS(X) = 0,
W-TS(X) = 0.
Step-by-step Execution
Check condition:
If TS(T1) < R-TS(X) → reject
If TS(T1) < W-TS(X) → reject
Here:
TS(T1)=5 > R-TS(X)=0
TS(T1)=5 > W-TS(X)=0 → Write allowed
Update:
W-TS(X)=5, X updated.
Check condition:
If TS(T2) < W-TS(X) → reject (T2 would read obsolete value)
Here:
TS(T2)=10 > W-TS(X)=5 → Read allowed
Update:
R-TS(X)=10
Final Outcome
• T1 writes first
• T2 reads later
• No rollback
• Serializability order: T1 → T2
This demonstrates a conflict resolved using timestamp ordering without deadlock or starvation.
2. Illustrate the Thomas Write Rule with a practical example and show how it differs from
basic time-stamp protocol.
If an older transaction tries to write after a newer write, it is rejected and rolled back.
Example
TS(T1) = 5
TS(T2) = 10
Operations:
Difference Summary
Lock-Based Protocols
Problems
• Deadlocks
• Cascading rollbacks
• No blocking → no deadlock
Problems
Comparison Table
Deadlocks Yes No
Blocking Yes No
4. Compare the working of two-phase locking protocol with the tree protocol in terms of
transaction safety and performance.
Working:
Performance:
• Causes deadlocks
Working:
Properties:
• Deadlock-free
Comparison Table
Pros
Cons
• Deadlocks possible
• Reduced throughput
Optimistic Concurrency Control
Pros
• No deadlock
Cons
Trade-off Summary
6. Devise your own deadlock prevention strategy using ordering of resource allocation and
explain how it works.
Example
T1 requests X → allowed
T2 requests Y → allowed
T1 requests Y → allowed (X < Y)
T2 requests X → not allowed (violates order)
7. Create a complete locking protocol that includes lock conversion, compatibility checks,
and deadlock avoidance.
1. Lock Types
• S (Shared) → read
• X (Exclusive) → write
2. Lock Conversion
• S → X allowed (upgrade)
• X → S allowed (downgrade)
• Rules:
3. Compatibility Matrix
S ✓ ×
X × ×
4. Deadlock Avoidance
Ensures no cycle.
Protocol Steps
• High concurrency
• No deadlocks
• Database
• Table
• Page
• Row
Uses intention locks (IS, IX, SIX) to coordinate locking at multiple levels.
Benefits
1. Improves Concurrency
3. Avoids Conflicts
Intention locks ensure safety:
• B-trees
• Index scans
Drawbacks
• Complex implementation
MODULE – 7
1. Explain how the CAP theorem influences the design of distributed NoSQL systems. (10
Marks)
CAP Theorem (proposed by Eric Brewer) states that a distributed database cannot
simultaneously guarantee all three properties:
2. Availability (A) – Every request gets a response, even if some nodes fail.
3. Partition Tolerance (P) – The system continues to work even when network failures
occur and nodes cannot communicate.
1. Trade-off Decisions
NoSQL databases are designed based on which two properties they prioritize:
2. Replication Strategies
AP systems replicate data asynchronously to maximize availability.
CP systems use synchronous replication to ensure consistent copies.
3. Consistency Models
CAP leads to different consistency levels:
o Causal Consistency
o Read-your-write consistency
5. Application-Specific Design
The choice depends on system requirements:
Conclusion
CAP theorem guides NoSQL architects to balance consistency, availability, and partition
tolerance, influencing core database design, replication, query behaviour, and application
suitability.
2. Compare the features of Document databases and Graph databases with real-world use
cases. (10 Marks)
3. User Profiles
User preferences and settings stored as JSON.
1. Social Networks
Represent friends, followers, relationships.
2. Recommendation Engines
“Users similar to you also bought…”
3. Fraud Detection
Detects relationship patterns between accounts, transactions.
Conclusion
Document databases focus on flexible storage of semi-structured data, while graph databases
excel at fast relationship querying and complex graph traversal.
Use Cases:
Caching (Redis), session storage, shopping cart data, leaderboards.
4. Explain the different types of NoSQL databases in detail. Highlight their data models,
use cases, and examples. (10 Marks)
1. Key–Value Stores
2. Document Databases
3. Column-Family Stores
• Data stored into rows and dynamic columns, grouped into families.
4. Graph Databases
Conclusion
5. Discuss in detail how NoSQL databases support Big Data analytics and give examples
from industry. (10 Marks)
1. Handling Volume
Designed for rapid reads/writes; useful for streaming and real-time analytics.
3. Variety Support
• JSON
• logs
• images
• clickstreams
4. Distributed Architecture
Works with:
• Hadoop
• Spark
• Kafka
• Flink
6. Schema Flexibility
• IoT Platforms
Use time-series NoSQL databases for sensor analytics (e.g., InfluxDB).
Conclusion
NoSQL provides scalable, flexible, and high-performance solutions needed for Big Data
analytics across e-commerce, social media, IoT, and finance industries.
6. Compare RDBMS and NoSQL databases in terms of schema design, query languages,
scalability, and consistency. (10 Marks)
Best For Banking, ERP, structured data Big Data, IoT, analytics, fast-changing data