Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions app/sem4/dbms/content/chapter4.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
export const Ch4Content = () => {
return (
<div className="course-content">
<p className="p-text">
<span className="font-semibold">Normalization</span> is the process of
organizing a database to reduce redundancy and improve data integrity by
breaking large tables into smaller, well-structured ones.
</p>

<hr className="my-6 border-[#c7a669] opacity-40" />

<section>
<h3 className="section-heading">
<span className="section-subheading">Why Normalize?</span>
</h3>
<ul className="section-list">
<li><span className="font-semibold">Insertion Anomaly:</span> cannot add data without unrelated data. Example: can&apos;t add a course unless a student is enrolled.</li>
<li><span className="font-semibold">Deletion Anomaly:</span> deleting one record accidentally removes other useful data.</li>
<li><span className="font-semibold">Update Anomaly:</span> updating one value requires changing it in many places.</li>
<li>Normalization solves all three by removing redundant data dependencies.</li>
</ul>
</section>

<hr className="my-6 border-[#c7a669] opacity-40" />

<section>
<h3 className="section-heading">
<span className="section-subheading">Functional Dependency</span>
</h3>
<ul className="section-list">
<li>A <span className="font-semibold">Functional Dependency (FD)</span> means one attribute determines another. Written as A → B.</li>
<li>Example: StudentID → StudentName (knowing the ID tells you the name).</li>
<li><span className="font-semibold">Partial Dependency:</span> a non-key attribute depends on part of a composite primary key.</li>
<li><span className="font-semibold">Transitive Dependency:</span> a non-key attribute depends on another non-key attribute.</li>
</ul>
<div className="tip-block">
<p>Exam Tip: FDs are the foundation of all normal forms. Master them first.</p>
</div>
</section>

<hr className="my-6 border-[#c7a669] opacity-40" />

<section>
<h3 className="section-heading">
<span className="section-subheading">1NF — First Normal Form</span>
</h3>
<ul className="section-list">
<li>A table is in 1NF if every column contains <span className="font-semibold">atomic (indivisible) values</span>.</li>
<li>No repeating groups or arrays in a single column.</li>
<li>Each row must be unique (has a primary key).</li>
</ul>
<div className="example-block">
<p className="font-semibold mb-1">Violation → Fix</p>
<pre>{`❌ Not 1NF:
StudentID | Courses
101 | DBMS, OS, CN

✅ 1NF:
StudentID | Course
101 | DBMS
101 | OS
101 | CN`}</pre>
</div>
</section>

<hr className="my-6 border-[#c7a669] opacity-40" />

<section>
<h3 className="section-heading">
<span className="section-subheading">2NF — Second Normal Form</span>
</h3>
<ul className="section-list">
<li>Must be in 1NF.</li>
<li>No <span className="font-semibold">partial dependencies</span> — every non-key attribute must depend on the <span className="font-semibold">entire</span> primary key.</li>
<li>Applies only when the primary key is composite.</li>
</ul>
<div className="example-block">
<p className="font-semibold mb-1">Violation → Fix</p>
<pre>{`❌ Not 2NF (PK = StudentID + CourseID):
StudentID | CourseID | StudentName | Grade
101 | CS401 | Zubair | A

StudentName depends only on StudentID (partial dependency).

✅ 2NF: Split into two tables:
Students(StudentID, StudentName)
Enrollments(StudentID, CourseID, Grade)`}</pre>
</div>
</section>

<hr className="my-6 border-[#c7a669] opacity-40" />

<section>
<h3 className="section-heading">
<span className="section-subheading">3NF — Third Normal Form</span>
</h3>
<ul className="section-list">
<li>Must be in 2NF.</li>
<li>No <span className="font-semibold">transitive dependencies</span> — non-key attributes must not depend on other non-key attributes.</li>
</ul>
<div className="example-block">
<p className="font-semibold mb-1">Violation → Fix</p>
<pre>{`❌ Not 3NF:
StudentID | DeptID | DeptName
101 | D01 | CSE

DeptName depends on DeptID (not on StudentID) — transitive.

✅ 3NF: Split:
Students(StudentID, DeptID)
Departments(DeptID, DeptName)`}</pre>
</div>
</section>

<hr className="my-6 border-[#c7a669] opacity-40" />

<section>
<h3 className="section-heading">
<span className="section-subheading">BCNF — Boyce-Codd Normal Form</span>
</h3>
<ul className="section-list">
<li>A stricter version of 3NF.</li>
<li>For every FD A → B, A must be a <span className="font-semibold">superkey</span>.</li>
<li>Handles cases where 3NF still has anomalies due to overlapping candidate keys.</li>
</ul>
<div className="tip-block">
<p>If a table is in BCNF, it is also in 3NF — but not vice versa. BCNF is stronger.</p>
</div>
</section>

<hr className="my-6 border-[#c7a669] opacity-40" />

<section>
<h3 className="section-heading">
<span className="section-subheading">Decomposition</span>
</h3>
<ul className="section-list">
<li><span className="font-semibold">Lossless Join:</span> splitting a table and rejoining gives back the original data exactly.</li>
<li><span className="font-semibold">Dependency Preservation:</span> all original FDs can still be checked in the decomposed tables.</li>
<li>BCNF decomposition always gives lossless joins but may lose dependency preservation.</li>
<li>3NF decomposition preserves both lossless join and dependency preservation.</li>
</ul>
</section>
</div>
);
};
126 changes: 126 additions & 0 deletions app/sem4/dbms/content/chapter5.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
export const Ch5Content = () => {
return (
<div className="course-content">
<p className="p-text">
A <span className="font-semibold">transaction</span> is a sequence of
database operations treated as a single unit. Concurrency control ensures
multiple transactions run simultaneously without conflicts.
</p>

<hr className="my-6 border-[#c7a669] opacity-40" />

<section>
<h3 className="section-heading">
<span className="section-subheading">ACID Properties</span>
</h3>
<ul className="section-list">
<li><span className="font-semibold">Atomicity:</span> all operations succeed, or none do. No partial execution.</li>
<li><span className="font-semibold">Consistency:</span> the database moves from one valid state to another.</li>
<li><span className="font-semibold">Isolation:</span> concurrent transactions do not interfere with each other.</li>
<li><span className="font-semibold">Durability:</span> once committed, changes persist even after a crash.</li>
</ul>
<div className="tip-block">
<p>Exam Tip: ACID is one of the most asked topics. Remember all four with the mnemonic: <span className="font-semibold">A</span>ll <span className="font-semibold">C</span>hanges <span className="font-semibold">I</span>solated &amp; <span className="font-semibold">D</span>urable.</p>
</div>
</section>

<hr className="my-6 border-[#c7a669] opacity-40" />

<section>
<h3 className="section-heading">
<span className="section-subheading">Transaction States</span>
</h3>
<ul className="section-list">
<li><span className="font-semibold">Active:</span> transaction is currently executing.</li>
<li><span className="font-semibold">Partially Committed:</span> last operation executed, not yet written to disk.</li>
<li><span className="font-semibold">Committed:</span> all changes written permanently to the database.</li>
<li><span className="font-semibold">Failed:</span> normal execution cannot continue.</li>
<li><span className="font-semibold">Aborted:</span> transaction rolled back; database restored to previous state.</li>
</ul>
<div className="example-block">
<p className="font-semibold mb-1">State Flow</p>
<pre>{`Active → Partially Committed → Committed
Active → Failed → Aborted`}</pre>
</div>
</section>

<hr className="my-6 border-[#c7a669] opacity-40" />

<section>
<h3 className="section-heading">
<span className="section-subheading">Concurrency Problems</span>
</h3>
<ul className="section-list">
<li><span className="font-semibold">Lost Update:</span> two transactions read and update the same data; one update overwrites the other.</li>
<li><span className="font-semibold">Dirty Read:</span> a transaction reads data written by another transaction that has not committed yet.</li>
<li><span className="font-semibold">Unrepeatable Read:</span> a transaction reads the same row twice and gets different values because another transaction updated it.</li>
<li><span className="font-semibold">Phantom Read:</span> a transaction re-executes a query and finds new rows added by another transaction.</li>
</ul>
</section>

<hr className="my-6 border-[#c7a669] opacity-40" />

<section>
<h3 className="section-heading">
<span className="section-subheading">Locking</span>
</h3>
<ul className="section-list">
<li><span className="font-semibold">Shared Lock (S):</span> allows reading. Multiple transactions can hold a shared lock simultaneously.</li>
<li><span className="font-semibold">Exclusive Lock (X):</span> allows reading and writing. Only one transaction can hold it; no other locks allowed.</li>
<li>A transaction must acquire the appropriate lock before accessing data.</li>
</ul>
</section>

<hr className="my-6 border-[#c7a669] opacity-40" />

<section>
<h3 className="section-heading">
<span className="section-subheading">Two-Phase Locking (2PL)</span>
</h3>
<ul className="section-list">
<li>A protocol to ensure serializability (correct concurrent execution).</li>
<li><span className="font-semibold">Growing Phase:</span> locks are acquired; no lock is released.</li>
<li><span className="font-semibold">Shrinking Phase:</span> locks are released; no new lock is acquired.</li>
<li>2PL guarantees conflict serializability but can cause deadlocks.</li>
</ul>
<div className="tip-block">
<p>Once a transaction releases its first lock, it enters the shrinking phase and cannot acquire new locks.</p>
</div>
</section>

<hr className="my-6 border-[#c7a669] opacity-40" />

<section>
<h3 className="section-heading">
<span className="section-subheading">Deadlock</span>
</h3>
<ul className="section-list">
<li>A deadlock occurs when two or more transactions wait for each other to release locks — forming a cycle.</li>
<li><span className="font-semibold">Detection:</span> use a wait-for graph; a cycle means deadlock.</li>
<li><span className="font-semibold">Prevention:</span> use timestamps (wait-die or wound-wait schemes).</li>
<li><span className="font-semibold">Recovery:</span> abort one transaction (the victim) to break the cycle.</li>
</ul>
<div className="example-block">
<p className="font-semibold mb-1">Deadlock Example</p>
<pre>{`T1 holds Lock(A), waits for Lock(B)
T2 holds Lock(B), waits for Lock(A)
→ Deadlock! Neither can proceed.`}</pre>
</div>
</section>

<hr className="my-6 border-[#c7a669] opacity-40" />

<section>
<h3 className="section-heading">
<span className="section-subheading">Timestamp-Based Concurrency Control</span>
</h3>
<ul className="section-list">
<li>Each transaction is assigned a unique timestamp when it starts.</li>
<li>Operations are ordered by timestamp to ensure serializability.</li>
<li><span className="font-semibold">Wait-Die:</span> older transaction waits; younger is aborted (dies).</li>
<li><span className="font-semibold">Wound-Wait:</span> older transaction aborts the younger (wounds it); younger waits if it&apos;s older.</li>
</ul>
</section>
</div>
);
};