⚡ CCSU Meerut · BCA 5th Semester · Exam Preparation
Introduction to DBMS BCA-501 Most Important Questions & Solved Exam Notebook
Master solved question bank of recurring CCSU examination questions (2014–2023) for Introduction to DBMS (BCA-501) with ER modeling, relational algebra, SQL queries, normalization (1NF to BCNF proofs), 2PL concurrency, and vector SVG diagrams.
Very Short Answer Questions & Core Database Concepts
CCSU Examination Blueprint: 5 Questions Compulsory • Total 15 Marks (75 Words Limit)
Q1. What is a Database Management System (DBMS)? State three critical advantages of a DBMS over conventional File Processing Systems.
A Database Management System (DBMS) is a specialized software suite designed to define, construct, manipulate, query, and maintain structured collections of interrelated data while enforcing access security and integrity constraints.
Three Critical Advantages over File Systems:
- Minimization of Data Redundancy & Inconsistency: In file systems, different departments duplicate identical student records, causing discrepancies when updated. DBMS centralizes data storage to eliminate uncontrolled duplication.
- Data Independence: Application programs are insulated from physical changes in storage layout or logical schema definitions.
- Transaction Support & Concurrency Control: DBMS guarantees ACID properties, preventing race conditions, dirty reads, and partial updates when multiple users access records simultaneously.
Q2. Explain the ANSI/SPARC Three-Schema Architecture. Differentiate between Physical and Logical Data Independence.
The Three-Schema Architecture divides database design into three distinct abstraction tiers: External Level (Views), Conceptual Level (Logical Structure/ER), and Internal Level (Physical Storage/B-Trees).
| Feature | Physical Data Independence | Logical Data Independence |
|---|---|---|
| Definition | The capacity to modify the internal schema without requiring changes to the conceptual or external schemas. | The capacity to modify the conceptual schema without requiring changes to external schemas or user applications. |
| Example | Switching disk storage hardware, changing compression algorithms, or adding B+ tree indexes. | Adding a new entity table, adding a new column to a relation, or splitting tables. |
| Attainability | Easier to achieve in relational systems. | Significantly harder to achieve because applications depend heavily on logical attributes. |
Q3. Define Entity, Attribute, Entity Set, and Relationship Set in an Entity-Relationship (ER) Model.
- Entity: A distinct real-world object or concept that is distinguishable from other objects (e.g. A specific student named "Rohit Sharma").
- Attribute: A descriptive property or characteristic that describes an entity (e.g.
RollNo,StudentName,Email,DOB). - Entity Set: A collection of all entities of the same type sharing common attributes (e.g. The set of all students in a college represented as
STUDENT). - Relationship Set: An association among two or more entities (e.g. Student Rohit
ENROLLED_INBCA Course). A mathematical relation on $E_1 imes E_2 imes \dots imes E_n$.
Q4. What is a Weak Entity Set? Explain Identifying Relationship and Partial Key (Discriminator) with an example.
A Weak Entity Set is an entity set that does not possess sufficient attributes to form a primary key of its own. It depends on the existence of an Identifying (Strong) Entity Set for identification.
- Identifying Relationship: The relationship connecting the weak entity set to its owner strong entity set (drawn with a double diamond in ER diagrams).
- Partial Key (Discriminator): A set of attributes that uniquely distinguishes weak entities belonging to the same strong entity (drawn with a dashed underline).
- Classic Example: In an employee database,
DEPENDENT(child/spouse) is a weak entity set identified byEmployeeIDof the strong entityEMPLOYEEcombined with the partial keyDependent_Name.
Q5. Differentiate between Super Key, Candidate Key, and Primary Key in Relational Database Theory.
- Super Key (SK): A single attribute or set of attributes that uniquely identifies every tuple within a relation. A super key may contain extraneous / redundant attributes (e.g.
{RollNo, PhoneNo, Email}). - Candidate Key (CK): A minimal super key having no proper subset that is itself a super key. Candidate keys have no redundant attributes (e.g.
{RollNo}and{Email}). - Primary Key (PK): The single candidate key selected by the database designer as the principal identification mechanism for the relation. It enforces uniqueness and never accepts NULL values.
Primary Key ⊆ Candidate Key ⊆ Super Key. All candidate keys are super keys, but not all super keys are candidate keys.
Q6. Explain Referential Integrity Constraint. What is the effect of ON DELETE CASCADE?
A Referential Integrity Constraint dictates that a value appearing in the Foreign Key column of a referencing table must match an existing primary key value in the referenced parent table, or else be NULL.
Action of ON DELETE CASCADE: If a record in the parent table is deleted, the DBMS automatically deletes all corresponding child records in the referencing table that reference that parent key, preventing "orphaned records" without triggering a foreign key violation error.
Q7. Contrast Data Definition Language (DDL) and Data Manipulation Language (DML) with standard SQL statements.
| Feature | DDL (Data Definition Language) | DML (Data Manipulation Language) |
|---|---|---|
| Purpose | Defines, creates, alters, or destroys the database structure/schema. | Manipulates, retrieves, inserts, modifies, or deletes row data. |
| SQL Commands | CREATE, ALTER, DROP, TRUNCATE, RENAME. |
SELECT, INSERT, UPDATE, DELETE. |
| Transaction Behavior | Auto-committed permanently. Cannot be rolled back. | Can be rolled back using ROLLBACK before a COMMIT. |
Q8. Differentiate between WHERE clause and HAVING clause in SQL.
| Criteria | WHERE Clause |
HAVING Clause |
|---|---|---|
| Target Level | Filters individual rows before grouping occurs. | Filters summarized groups produced by GROUP BY. |
| Aggregate Functions | Cannot contain aggregate functions (e.g. WHERE SUM(sal) > 5000 is INVALID). |
Specifically designed to evaluate aggregate expressions (e.g. HAVING COUNT(*) > 5). |
| Position in Query | Placed before the GROUP BY clause. |
Placed strictly after the GROUP BY clause. |
Q9. What is a View in SQL? State two major advantages and one limitation of Views.
A View is a virtual table whose contents are defined by an underlying SQL query: CREATE VIEW ViewName AS SELECT .... A view stores no physical records on disk; instead, the query is executed dynamically whenever the view is queried.
- Advantage 1 (Data Security): Hides sensitive columns (e.g., hiding
SalaryorPasswordHashfrom junior HR staff by providing a filtered view). - Advantage 2 (Query Simplification): Replaces complex multi-table joins with a simple
SELECT * FROM StudentCourseView. - Limitation: Views containing joins, aggregate functions,
DISTINCT, orGROUP BYare read-only and cannot be updated directly via DML (INSERT/UPDATE/DELETE).
Q10. Define Functional Dependency ($X o Y$). State Armstrong's three primary axioms.
In relation schema $R$, attribute set $Y$ is Functionally Dependent on $X$ ($X o Y$) if and only if whenever two tuples $t_1, t_2 \in R$ agree on the values of $X$ ($t_1[X] = t_2[X]$), they must also agree on the values of $Y$ ($t_1[Y] = t_2[Y]$).
Armstrong's Three Primary Axioms:
- Axiom of Reflexivity: If $Y \subseteq X$, then $X o Y$ (Trivial dependency).
- Axiom of Augmentation: If $X o Y$, then $XZ o YZ$ for any attribute set $Z$.
- Axiom of Transitivity: If $X o Y$ and $Y o Z$, then $X o Z$.
Q11. Define First Normal Form (1NF) and Second Normal Form (2NF). What constitutes a Partial Dependency?
- First Normal Form (1NF): A relation is in 1NF if all domain values are atomic (indivisible), meaning no attribute contains multivalued lists, sets, or nested repeating groups.
- Second Normal Form (2NF): A relation is in 2NF if it is in 1NF and no non-prime attribute is partially dependent on any candidate key. Every non-prime attribute must be fully functionally dependent on the entire composite primary key.
- Partial Dependency: Occurs when a non-prime attribute depends on a proper subset of a composite candidate key rather than the complete key (e.g. In key $\{A, B\}$, dependency $A o C$ where $C$ is non-prime is a partial dependency).
Q12. Differentiate between 3NF and BCNF (Boyce-Codd Normal Form) with formal mathematical conditions.
For every non-trivial functional dependency $X o Y$ in relation $R$:
| Normal Form | Mandatory Condition for $X o Y$ | Rigidity Level |
|---|---|---|
| Third Normal Form (3NF) | Either $X$ is a Super Key, OR $Y$ is a Prime Attribute (member of some candidate key). | Relaxed (Allows functional dependencies where determinant $X$ is not a super key if $Y$ is prime). Always guarantees dependency preservation. |
| Boyce-Codd Normal Form (BCNF) | $X$ MUST BE A SUPER KEY (No exceptions allowed). | Strict. Eliminates all anomalies based on functional dependencies, but dependency preservation cannot always be guaranteed. |
Q13. Explain the ACID Properties of a database transaction.
- Atomicity ("All or Nothing"): Guarantees that either all operations of a transaction execute to completion and commit, or the entire transaction is rolled back leaving no partial changes. Managed by the Recovery Manager.
- Consistency: Ensures that execution of a transaction preserves database invariants, taking the database from one valid consistent state to another.
- Isolation: Ensures that concurrently executing transactions are invisible to each other until committed, appearing as if executed serially. Managed by Concurrency Control Manager.
- Durability: Once a transaction commits, its updates persist permanently in non-volatile disk storage, surviving even system crashes. Managed by Log Manager.
Q14. What is a Dirty Read anomaly (Temporary Update problem) in concurrent transaction processing?
A Dirty Read occurs when Transaction $T_2$ reads a data item that has been updated by Transaction $T_1$, but $T_1$ has not yet committed. If $T_1$ subsequently fails and is rolled back (aborted), the data value read by $T_2$ is invalid ("dirty" data that never legally existed in the database).
Schedule Trace: $W_1(A=500) o R_2(A=500) o ext{Abort}_1 o ext{Rollback}(A=100)$. Here $T_2$ computed actions based on phantom value 500.
Q15. What is the Two-Phase Locking (2PL) Protocol? Differentiate between the Growing Phase and Shrinking Phase.
The Two-Phase Locking (2PL) protocol is a concurrency control mechanism guaranteeing conflict serializability. It mandates that every transaction acquire and release locks in two discrete phases:
- 1. Growing Phase (Expanding): The transaction may obtain new locks (Shared or Exclusive) but cannot release any lock.
- 2. Shrinking Phase (Contracting): The transaction may release locks but cannot acquire any new locks.
Analytical Architectures, Relational Algebra & Schema Proofs
CCSU Examination Blueprint: Attempt Any 2 of 3 Questions • Total 15 Marks (~200 Words + Schemas/Diagrams)
Q16. Explain the ANSI/SPARC Three-Level Database Architecture with a neat diagram. Discuss how it provides Physical and Logical Data Independence.
The ANSI/SPARC Architecture separates the physical database storage from user application views through three distinct levels of abstraction:
- External Level (User Views): Tailored interfaces representing only relevant portions of the database for specific user roles while hiding irrelevant or confidential records.
- Conceptual Level: Defines the complete logical structure of the entire enterprise database (entities, relationships, data types, constraints). Independent of physical storage devices.
- Internal Level: Governs physical storage layouts on disk drives, block clustering, access paths, hashing schemes, and index structures.
Q17. Discuss the Fundamental and Join Operations in Relational Algebra. Write formal algebraic expressions with clear examples.
Relational Algebra is a procedural query language consisting of a set of operations that take one or two relations as input and produce a new relation as output.
| Operation | Operator Symbol | Purpose & Formal Syntax | Example Expression |
|---|---|---|---|
| Selection | $\sigma$ (Sigma) | Filters tuples (rows) satisfying a predicate $p$: $\sigma_p(R)$ | $\sigma_{ ext{Age} > 20 \land ext{City} = ext{'Delhi'}}( ext{Student})$ |
| Projection | $\pi$ (Pi) | Selects specified columns (attributes) and discards duplicates: $\pi_{A_1, \dots, A_k}(R)$ | $\pi_{ ext{RollNo, Name}}( ext{Student})$ |
| Cartesian Product | $ imes$ (Cross) | Combines every tuple of $R$ with every tuple of $S$: $R imes S$ | $ ext{Student} imes ext{Course}$ ($n_1 imes n_2$ tuples) |
| Union | $\cup$ (Union) | Returns tuples in $R$, $S$, or both (requires union-compatibility): $R \cup S$ | $\pi_{ ext{Name}}( ext{BCA\_Stud}) \cup \pi_{ ext{Name}}( ext{BBA\_Stud})$ |
| Set Difference | $-$ (Minus) | Returns tuples present in $R$ but not in $S$: $R - S$ | $ ext{Enrolled2022} - ext{Enrolled2023}$ |
| Natural Join | $owtie$ (Bowtie) | Combines tuples of $R$ and $S$ having identical values on common attributes: $R owtie S$ | $ ext{Student} owtie ext{Enrollment}$ |
Q18. Explain SQL Aggregate Functions. Given the relation Employee(EmpID, EmpName, DeptName, Salary, City), write SQL queries to find departments with total payroll > ₹5,00,000 and count of employees in each department located in 'Noida'.
Aggregate Functions perform calculations on a set of column values and return a single scalar summary value: COUNT(), SUM(), AVG(), MIN(), MAX(). All aggregate functions (except COUNT(*)) automatically ignore NULL values.
SQL Query 1: Departments with Total Payroll Exceeding ₹5,00,000
SELECT DeptName, SUM(Salary) AS TotalPayroll, COUNT(EmpID) AS HeadCount
FROM Employee
GROUP BY DeptName
HAVING SUM(Salary) > 500000;
SQL Query 2: Count of Employees per Department located strictly in 'Noida'
SELECT DeptName, COUNT(*) AS TotalEmployees, AVG(Salary) AS AvgSalary
FROM Employee
WHERE City = 'Noida'
GROUP BY DeptName;
FROM → WHERE (row filtering) → GROUP BY (bucketing) → HAVING (group filtering) → SELECT → ORDER BY.
Q19. Describe the step-by-step algorithmic rules for converting an Entity-Relationship (ER) diagram into Relational Schema tables.
- Step 1 (Strong Entity Sets): Create a table for each strong entity. Include all simple attributes. Choose the primary key. For composite attributes, include only their simple component sub-attributes.
- Step 2 (Weak Entity Sets): Create a separate table. Primary key is formed by the Primary Key of the identifying strong entity + the Partial Key (Discriminator) of the weak entity.
- Step 3 (Multivalued Attributes): Create a distinct dedicated table containing the multivalued attribute plus the primary key of the parent entity as a foreign key. The composite of both columns forms the primary key.
- Step 4 (1:1 Relationships): Merge into a single table if total participation on both sides, or place the primary key of one entity as a Foreign Key (with
UNIQUEconstraint) in the other table. - Step 5 (1:N Binary Relationships): Place the primary key of the "1" side as a Foreign Key in the table representing the "N" side entity.
- Step 6 (M:N Binary Relationships): Create a brand-new Junction / Relationship Table. Its primary key is the composite combination of primary keys from both participating entity sets. Any relationship descriptive attributes become columns in this junction table.
Q20. Given relation schema $R(A, B, C, D, E)$ and set of functional dependencies $F = \{A o B, BC o D, E o C\}$. Compute the attribute closures $(A)^+$ and $(AE)^+$. Determine all candidate keys of $R$.
1. Computing Attribute Closures:
- Closure of $A$, denoted $(A)^+$:
- Initial set: $(A)^+ = \{A\}$
- Apply $A o B$: $(A)^+ = \{A, B\}$
- No other FD can be triggered ($BC o D$ needs $C$; $E o C$ needs $E$).
- Result: $(A)^+ = \{A, B\}$ (Cannot determine all attributes, so $A$ is not a key).
- Closure of $AE$, denoted $(AE)^+$:
- Initial set: $(AE)^+ = \{A, E\}$
- Apply $A o B$: $(AE)^+ = \{A, B, E\}$
- Apply $E o C$: $(AE)^+ = \{A, B, C, E\}$
- Apply $BC o D$: $(AE)^+ = \{A, B, C, D, E\} = R$
- Result: $(AE)^+ = \{A, B, C, D, E\}$. Since $(AE)^+$ derives all attributes of $R$, $AE$ is a Super Key!
2. Finding All Candidate Keys:
- Examine the Right-Hand Side (RHS) of all FDs in $F$: Attributes $B, D, C$ appear on RHS. Attributes $A$ and $E$ never appear on the RHS of any FD.
- Therefore, $A$ and $E$ must strictly be part of every candidate key.
- Since $(AE)^+ = R$ and neither proper subset $(A)^+ = \{A,B\} eq R$ nor $(E)^+ = \{E,C\} eq R$ can determine $R$, $AE$ is strictly minimal.
- Conclusion: The relation has exactly one Candidate Key: $\{AE\}$.
Q21. Differentiate between Conflict Serializability and View Serializability. How does a Precedence Graph test for conflict serializability?
| Feature | Conflict Serializability | View Serializability |
|---|---|---|
| Equivalence Basis | Schedule $S$ is conflict serializable if it can be transformed into a serial schedule by swapping non-conflicting adjacent operations. | Schedule $S$ is view serializable if it is view equivalent to some serial schedule (preserves initial read, updated read, and final write). |
| Computational Complexity | Fast $O(V + E)$ cycle detection via Precedence Graph. | NP-Complete problem (computationally intractable for large schedules). |
| Coverage | Conflict Serializability ⊂ View Serializability. Every conflict serializable schedule is view serializable, but not vice-versa (e.g. schedules with blind writes). |
Precedence Graph (Serialization Graph) Algorithm:
- Create a directed graph node for each committed transaction $T_i$.
- Draw a directed edge $T_i o T_j$ if $T_i$ and $T_j$ execute conflicting operations on data item $Q$ ($R_i(Q)/W_j(Q)$, $W_i(Q)/R_j(Q)$, or $W_i(Q)/W_j(Q)$) and $T_i$'s operation precedes $T_j$'s operation.
- Theorem: A concurrent schedule is Conflict Serializable if and only if its Precedence Graph contains NO directed cycles. Topological sort of the acyclic graph gives the equivalent serial schedule.
Q22. Explain Deadlock handling in DBMS. Compare the Wait-Die and Wound-Wait timestamp prevention schemes with a comparison table.
A Deadlock is a state where two or more transactions are in a simultaneous circular wait, each holding a lock on a data item that another transaction requires.
| Criteria | Wait-Die Scheme (Non-Preemptive) | Wound-Wait Scheme (Preemptive) |
|---|---|---|
| Older requests lock held by Younger | Older transaction is allowed to WAIT ($TS(T_i) < TS(T_j)$ → Wait). | Older transaction WOUNDS (preempts & rolls back) younger transaction ($TS(T_i) < TS(T_j)$ → Rollback $T_j$). |
| Younger requests lock held by Older | Younger transaction DIES (aborted and rolled back) ($TS(T_i) > TS(T_j)$ → Abort $T_i$). | Younger transaction is allowed to WAIT until older transaction finishes ($TS(T_i) > TS(T_j)$ → Wait). |
| Starvation Avoidance | When rolled back, aborted transaction restarts with its original timestamp so it eventually becomes oldest. | Minimizes rollbacks; tends to abort fewer transactions than Wait-Die. |
Q23. Explain Log-Based Recovery in DBMS. Compare Deferred Database Modification vs Immediate Database Modification with Checkpointing.
A System Log is an append-only sequential file on stable disk storage recording all database modifications: <T, start>, <T, X, old_val, new_val>, <T, commit>. Write-Ahead Logging (WAL) requires log records to flush to disk before actual data pages are written.
| Feature | Deferred Modification | Immediate Modification |
|---|---|---|
| Write to Disk | Disk writes deferred until after transaction commits. | Updates may be written to disk while transaction is still active. |
| Log Contents | Records only new values: <T, X, new_val>. |
Records both old and new values: <T, X, old_val, new_val>. |
| Crash Recovery | Requires only REDO operations. (No undo ever needed). | Requires both UNDO (for uncommitted transactions) and REDO (for committed transactions). |
<checkpoint L> record. During crash recovery, the recovery manager does not need to scan the entire log from the beginning of time—only scanning back to the most recent checkpoint.
Master Long Answer Questions, Architectural Blueprints & SVG Diagrams
CCSU Examination Blueprint: Attempt Any 3 of 5 Questions • Total 45 Marks (~500+ Words + Schemas + Diagrams)
Q24. Design a comprehensive Entity-Relationship (ER) Model for a University Management System capturing Students, Courses, Instructors, Departments, and Enrollments. Explain ER notations and convert the design into normalized Relational Tables with DDL schemas and integrity constraints.
1. ER Modeling Symbols & Notations:
- Entity (Rectangle): Represents real-world object sets (e.g.,
STUDENT,COURSE). - Weak Entity (Double Rectangle): Entity dependent on strong owner (e.g.,
DEPENDENT). - Attributes (Ovals): Key Attribute (Underlined text), Multivalued Attribute (Double Oval, e.g.
Phone_Numbers), Composite Attribute (Tree of sub-ovals, e.g.Name → First, Last), Derived Attribute (Dashed Oval, e.g.Agederived fromDOB). - Relationship (Diamond): Association connecting entities (e.g.,
ENROLLED_IN). Identifying relationship for weak entities is drawn with a Double Diamond.
2. Converted Relational Tables & SQL DDL Schemas:
-- 1. Department Table
CREATE TABLE Department (
DeptID VARCHAR(10) PRIMARY KEY,
DeptName VARCHAR(50) NOT NULL,
Building VARCHAR(50)
);
-- 2. Student Table (1:N with Department)
CREATE TABLE Student (
RollNo INT PRIMARY KEY,
FirstName VARCHAR(30) NOT NULL,
LastName VARCHAR(30),
Email VARCHAR(100) UNIQUE NOT NULL,
DOB DATE,
DeptID VARCHAR(10),
CONSTRAINT fk_stud_dept FOREIGN KEY (DeptID)
REFERENCES Department(DeptID) ON DELETE SET NULL
);
-- 3. Course Table (1:N with Department)
CREATE TABLE Course (
CourseID VARCHAR(15) PRIMARY KEY,
CourseTitle VARCHAR(100) NOT NULL,
Credits INT CHECK (Credits > 0),
DeptID VARCHAR(10),
CONSTRAINT fk_course_dept FOREIGN KEY (DeptID)
REFERENCES Department(DeptID) ON DELETE CASCADE
);
-- 4. Junction Table for M:N Relationship: Enrolled_In
CREATE TABLE Enrollment (
RollNo INT,
CourseID VARCHAR(15),
Semester INT NOT NULL,
AcademicYear INT NOT NULL,
Grade CHAR(2),
PRIMARY KEY (RollNo, CourseID, Semester, AcademicYear),
CONSTRAINT fk_enr_student FOREIGN KEY (RollNo)
REFERENCES Student(RollNo) ON DELETE CASCADE,
CONSTRAINT fk_enr_course FOREIGN KEY (CourseID)
REFERENCES Course(CourseID) ON DELETE CASCADE
);
Q25. Express the following database retrieval problems in BOTH Relational Algebra and SQL using the schema: Student(RollNo, Name, DeptID), Course(CourseID, Title, Credits), and Enrollment(RollNo, CourseID, Grade).
Query 1: Find names of all students who scored an 'A' grade in 'DBMS'
- Relational Algebra:
$$\pi_{ ext{Name}} \left( \sigma_{ ext{Title} = ext{'DBMS'} \land ext{Grade} = ext{'A'}} ( ext{Student} owtie ext{Enrollment} owtie ext{Course}) ight)$$ - SQL Formulation:
SELECT S.Name FROM Student S JOIN Enrollment E ON S.RollNo = E.RollNo JOIN Course C ON E.CourseID = C.CourseID WHERE C.Title = 'DBMS' AND E.Grade = 'A';
Query 2: Find all students who have enrolled in EVERY course offered (Division Operation $R \div S$)
- Relational Algebra:
$$\pi_{ ext{RollNo, CourseID}}( ext{Enrollment}) \div \pi_{ ext{CourseID}}( ext{Course})$$ - SQL Formulation (Correlated NOT EXISTS Subqueries):
SELECT S.RollNo, S.Name FROM Student S WHERE NOT EXISTS ( SELECT C.CourseID FROM Course C WHERE NOT EXISTS ( SELECT E.CourseID FROM Enrollment E WHERE E.RollNo = S.RollNo AND E.CourseID = C.CourseID ) );
Query 3: Find courses that have never been taken by any student (Outer Join / Set Difference)
- Relational Algebra:
$$\pi_{ ext{CourseID, Title}}( ext{Course}) - \pi_{ ext{CourseID, Title}}( ext{Course} owtie ext{Enrollment})$$ - SQL Formulation:
SELECT C.CourseID, C.Title FROM Course C LEFT JOIN Enrollment E ON C.CourseID = E.CourseID WHERE E.RollNo IS NULL;
Q26. Explain Database Anomalies in unnormalized schemas. State the formal definition of 1NF, 2NF, 3NF, and BCNF. Given relation $R(A, B, C, D, E)$ with functional dependencies $F = \{A o B, BC o D, D o E, E o A\}$, decompose $R$ into BCNF and prove whether the decomposition is Lossless and Dependency Preserving.
1. Database Anomalies in Poor Schema Design:
- Insertion Anomaly: Cannot insert an independent fact without artificially creating unrelated entities (e.g., cannot add a new course without enrolling a student if course details reside in student table).
- Deletion Anomaly: Deleting one record inadvertently erases vital unrelated data (e.g., deleting the last student enrolled in a course erases all information about that course).
- Update Anomaly: Data redundancy forces identical values to be updated in thousands of rows. If one row is missed, data becomes inconsistent.
2. Normalization Analysis & BCNF Decomposition:
Given $R(A, B, C, D, E)$ with $F = \{A o B, BC o D, D o E, E o A\}$.
Candidate Keys of $R$:
- $(AC)^+ = \{A, C, B, D, E\} = R \implies AC$ is a Candidate Key.
- $(EC)^+ = \{E, C, A, B, D\} = R \implies EC$ is a Candidate Key.
- $(DC)^+ = \{D, C, E, A, B\} = R \implies DC$ is a Candidate Key.
- $(BC)^+ = \{B, C, D, E, A\} = R \implies BC$ is a Candidate Key.
- Prime Attributes: $A, B, C, D, E$ (All attributes are prime!).
- 3NF Check: Because all RHS attributes are prime, every FD trivially satisfies 3NF! Thus, $R$ is already in 3NF.
BCNF Violation Check:
- FD $A o B$: Here determinant $A$ is NOT a superkey (only $AC, EC, DC, BC$ are keys). $A o B$ strictly violates BCNF!
- FD $D o E$: Determinant $D$ is NOT a superkey. Violates BCNF.
- FD $E o A$: Determinant $E$ is NOT a superkey. Violates BCNF.
BCNF Decomposition Steps:
- Decompose $R$ using violating FD $A o B$:
- $R_1(A, B)$ with key $A$. Since $A$ is key, $R_1$ is in BCNF.
- $R_2(A, C, D, E) = R - \{B\}$.
- In $R_2$, test $D o E$: Determinant $D$ is not a key for $R_2$ (key is $AC, DC, EC$). Decompose $R_2$:
- $R_{21}(D, E)$ with key $D$. (In BCNF).
- $R_{22}(A, C, D) = R_2 - \{E\}$ with key $AC$. (In BCNF).
Final BCNF Relations: $R_1(A, B)$, $R_{21}(D, E)$, $R_{22}(A, C, D)$.
3. Verification of Lossless Join & Dependency Preservation:
- Lossless Join Test:
$R_1 \cap R_2 = \{A\}$. Since $A$ is a candidate key for $R_1$ ($A o B$), the first split is lossless.
$R_{21} \cap R_{22} = \{D\}$. Since $D$ is key for $R_{21}$ ($D o E$), the second split is lossless.
Conclusion: The decomposition is strictly LOSSLESS. - Dependency Preservation Test:
$A o B$ is in $R_1$. $D o E$ is in $R_{21}$.
However, $BC o D$ cannot be tested within any single decomposed table without joining $R_1$ and $R_{22}$.
Conclusion: The decomposition is NOT Dependency Preserving. (This illustrates the classic trade-off: 3NF preserves all dependencies, whereas BCNF eliminates all anomalies but may sacrifice dependency preservation).
Q27. Draw and explain the Transaction State Transition Diagram. Detail the four classic Concurrent Execution Anomalies (Dirty Read, Lost Update, Unrepeatable Read, and Phantom Read) with schedule execution traces.
1. Transaction State Transition Architecture:
2. The Four Major Concurrency Anomalies:
| Anomaly | Operation Pattern | Harmful Impact / Real-World Scenario |
|---|---|---|
| 1. Lost Update Problem | $W_1(X) o W_2(X)$ overwrite | Two transactions read the same bank balance (₹1,000). $T_1$ adds ₹200 ($W_1(1200)$); concurrently $T_2$ withdraws ₹100 ($W_2(900)$). $T_2$'s write obliterates $T_1$'s deposit. ₹200 vanishes permanently! |
| 2. Dirty Read Problem (WR Conflict) | $W_1(X) o R_2(X) o ext{Abort}_1$ | $T_1$ updates balance to ₹5,000 but crashes and rolls back to ₹1,000. Meanwhile, $T_2$ read the uncommitted ₹5,000 value and dispatched goods to the customer based on a phantom balance. |
| 3. Unrepeatable Read Problem (RW Conflict) | $R_1(X) o W_2(X) o R_1(X)$ mismatch | $T_1$ reads item price as ₹50. Before $T_1$ completes, $T_2$ updates price to ₹80 and commits. When $T_1$ re-reads price to generate customer invoice, the value has mysteriously altered mid-transaction! |
| 4. Phantom Read Problem | $R_1( ext{range}) o ext{Insert}_2( ext{row}) o R_1( ext{range})$ | $T_1$ queries all students with GPA > 9.0 (returns 4 rows). $T_2$ inserts a new genius student with GPA 9.8. When $T_1$ re-runs the identical query, 5 rows appear ("phantom record"). |
Q28. Discuss the Two-Phase Locking (2PL) Protocol in detail. Explain Shared (S) vs Exclusive (X) locks, Strict 2PL, and Rigorous 2PL. Prove why 2PL guarantees Conflict Serializability, and discuss why basic 2PL is susceptible to deadlocks and cascading rollbacks.
1. Lock Modes & Lock Compatibility Matrix:
- Shared Lock (S-Lock): Requested for read-only access ($R(Q)$). Multiple concurrent transactions can hold S-locks simultaneously on the same item.
- Exclusive Lock (X-Lock): Requested for write access ($W(Q)$). Only one transaction can hold an X-lock; all other requests are denied.
| Current Lock \ Requested Lock | Shared Lock (S) | Exclusive Lock (X) |
|---|---|---|
| Shared Lock (S) | ✅ Compatible (Granted) | ❌ Incompatible (Must Wait) |
| Exclusive Lock (X) | ❌ Incompatible (Must Wait) | ❌ Incompatible (Must Wait) |
2. Variations of Two-Phase Locking:
- Basic 2PL: Locks can be released incrementally during the shrinking phase. Disadvantage: Vulnerable to cascading aborts and deadlocks!
- Strict 2PL: Mandates that all Exclusive (X) locks held by a transaction must be retained until the transaction commits or aborts. Benefit: Completely prevents dirty reads and cascading rollbacks!
- Rigorous 2PL: Mandates that ALL locks (both Shared and Exclusive) must be held until transaction commit/abort. Transactions serialize strictly in the order of their commit points.
Q29. Explain Deadlock Detection using Wait-For Graphs (WFG). How is a victim selected for rollback? Describe the complete ARIES / Log Checkpoint Crash Recovery Algorithm with UNDO and REDO lists.
1. Deadlock Detection via Wait-For Graph (WFG):
A Wait-For Graph is a directed graph $G = (V, E)$ where vertices $V$ represent active transactions and edges $E$ represent dependencies. A directed edge $T_i o T_j$ exists if $T_i$ is waiting for $T_j$ to release a lock on a data item. Theorem: A deadlock exists if and only if the Wait-For Graph contains a directed cycle.
2. Crash Recovery Algorithm with Checkpointing:
- Step 1 (Initialize Lists): At the latest checkpoint, load the active transaction list $L$. Set $ ext{UNDO-LIST} = L$ and $ ext{REDO-LIST} = \emptyset$.
- Step 2 (Forward Scan from Checkpoint to Failure Point):
- If log entry is
<T, start>, add $T$ to $ ext{UNDO-LIST}$. - If log entry is
<T, commit>or<T, abort>, move $T$ from $ ext{UNDO-LIST}$ to $ ext{REDO-LIST}$.
- If log entry is
- Step 3 (REDO Phase): Replay updates of all transactions in $ ext{REDO-LIST}$ forward from checkpoint using log new values to restore committed updates to disk.
- Step 4 (UNDO Phase): Scan backwards and undo all updates of transactions remaining in $ ext{UNDO-LIST}$ by restoring original old values, ensuring Atomicity.
Q30. Compare File Organization and Indexing techniques in DBMS. Explain Dense vs Sparse Indexing. Detail the internal node structure of B+ Trees with an architectural diagram and explain why B+ Trees are preferred over standard B-Trees for database disk storage.
1. Dense Index vs Sparse Index:
- Dense Index: Contains an index record for every single search-key value in the data file. Fast direct lookup, but consumes significant disk storage.
- Sparse Index: Contains an index record only for selected search-key values (typically one entry per disk block). Consumes minimal memory, but requires sequential scanning within the block. Can only be built if the data file is physically sorted on the search key.
2. Why B+ Trees are Preferred over Standard B-Trees:
| Criteria | Standard B-Tree | B+ Tree (Industry Standard) |
|---|---|---|
| Data Pointer Storage | Data record pointers stored in both internal nodes and leaf nodes. | Data pointers stored exclusively in leaf nodes. Internal nodes store only router keys. |
| Node Fanout & Tree Height | Lower fanout because data pointers consume internal node block space. Result: Taller tree (more disk I/O). | Much higher fanout. More keys fit in a single disk block. Result: Shorter tree (typically 3-4 levels for millions of records). |
Range Queries (e.g. WHERE Age BETWEEN 20 AND 30) |
Requires expensive in-order tree traversal jumping up and down disk blocks. | Extremely fast $O(K)$ sequential scan because all leaf nodes are connected via a contiguous doubly-linked list. |