82.8 KB · commit 40bb182
| year | 2023 |
|---|---|
| exam | B.Sc. Engineering 2nd Year Even Semester Examination, 2023 |
| course_code | ECE 2215 |
| course_title | Database Systems |
| full_marks | 60 |
| time | 3 Hours |
| layer | explanation |
← Prev: 2021 | Exam-Style Layer | Original Question Paper | Next: 2024 →
Topic: T02.5 · Design a full E-R diagram for a scenario · Section A · CLO4
Question.
Draw an ER diagram for RUET Central Library Management System. You have to consider the entities mentioned below:
(i) Books (ii) Members (iii) Staff (iv) Borrowing (v) Reservations
Answer.
What the examiner wants.
An E-R diagram featuring the exact 5 entity sets specified in the question: Books, Members, Staff, Borrowing, and Reservations (5 marks). All entities must have attributes and primary keys, connected with meaningful relationships and cardinalities.
Key idea.
Borrowing and Reservations are often modeled as relationships in simpler designs. But the prompt explicitly requires them as entities. So we model both as independent entity sets with their own unique IDs and transaction dates.
Step-by-step solution.
Design Note: Borrowing and Reservations are explicitly specified as entity sets in the prompt; each is modeled with its own unique identifier and transaction attributes.
Entity Sets & Attributes:
book_id (PK), isbn, title, author, edition.member_id (PK), name, type, department.staff_id (PK), name, designation.borrow_id (PK), borrow_date, due_date, return_date.res_id (PK), res_date, status.Relationships:
Issues (1:N): A staff member processes multiple borrowings.Borrows (1:N): A member initiates multiple borrowings.Includes (N:1): A borrowing record links to the specific book borrowed.Reserves (1:N): A member makes multiple book reservations.For_Book (N:1): A reservation is placed for a specific book.
Figure: RUET Central Library Management System E-R Diagram
Check.
Entity checklist:
BOOKS with PK book_id ✓MEMBERS with PK member_id ✓STAFF with PK staff_id ✓BORROWING with PK borrow_id ✓RESERVATIONS with PK res_id ✓Exam tip.
Start your answer with the design note stating that Borrowing and Reservations are modeled as entity sets. Then draw all 5 as rectangles.
Sources.
Topic: T01.2 · File system vs DBMS · Section A · CLO1 (Repeated question: Also asked in 2019 | Solved in T01)
Question. What are the advantages of DBMS over file processing system?
Answer.
What the examiner wants.
A brief statement on why a DBMS is important (~1 mark) and a structured list of at least 4 to 5 key advantages over file systems (~2 marks).
Key idea.
A DBMS provides a central, reliable layer between applications and physical storage. Its advantages directly fix the classic drawbacks of file processing systems: duplicate data, lack of ad-hoc access, and crash vulnerability.
Step-by-step solution.
Importance of DBMS:
A DBMS provides centralized, secure, and coordinated control over an organization's data. It replaces scattered operating system files and ensures that data remains reliable, shared, and recoverable during hardware or software crashes.
Advantages of DBMS over File Processing Systems:
Variant for 2023 Q.1(b) (3 marks): Focus directly on the 5 advantages over file processing systems; omit the general importance statement.
Check.
Quick self-test:
Exam tip.
List 5 numbered advantages with bold titles. This guarantees full marks even if an examiner deducts for a brief point.
Sources.
Topic: T01.5 · DDL vs DML · Section A · CLO1
Question. Explain DDL and DML with example.
Answer.
What the examiner wants.
A concise definition and a valid SQL example for DDL (1 mark), and a concise definition and a valid SQL example for DML (1 mark).
Key idea.
DDL sets up the schema and tables. DML queries and manipulates the records stored within those tables.
Step-by-step solution.
CREATE TABLE instructor (
ID CHAR(5),
name VARCHAR(20),
dept_name VARCHAR(20),
salary NUMERIC(8,2)
);
SELECT name FROM instructor WHERE dept_name = 'Comp. Sci.';
Check.
Classification check:
DROP TABLE student; → DDL (modifies schema).INSERT INTO instructor VALUES ('10101', 'Srinivasan', 'Comp. Sci.', 65000); → DML (modifies data).Exam tip.
Keep the explanation to 1 sentence per term, followed immediately by a clean 4-line SQL statement.
Sources.
Topic: T08.8 · Normalize an unnormalized table → 1NF → 2NF → 3NF · Section A · CLO4
Question.
Consider a university tracking students, their courses and exam scores. A sample table is given below. Step by step convert this to 3NF.
| S_ID | S-Name | Courses | Instructors | Grades |
|---|---|---|---|---|
| 1 | Alice | Math, Physics | Dr. Smith, Dr. Brown | A, B+ |
| 2 | Bob | Chemistry | Dr. White | A- |
| 3 | Charlie | Math, Biology, Chemistry | Dr. Smith, Dr. Gray, Dr. White | B+, A-, A |
Answer.
What the examiner wants.
Step-by-step conversion starting from unnormalized table to 1NF (atomic rows, 2 marks), then to 2NF eliminating partial dependencies (2 marks), and checking/verifying 3NF (2 marks).
Key idea.
Flatten the comma-separated lists to get 1NF. Notice that student names depend on student ID, and instructor depends on course. These are partial dependencies on the composite key (S_ID, Course). Splitting into STUDENT, COURSE, and ENROLLMENT achieves 2NF. Since there are no further transitive dependencies, the tables are also in 3NF.
Step-by-step solution.
The sample table violates 1NF because the attributes Courses, Instructors, and Grades contain multi-valued entries.
To achieve 1NF, we flatten each multi-valued row into individual atomic records:
| S_ID | S-Name | Course | Instructor | Grade |
|---|---|---|---|---|
| 1 | Alice | Math | Dr. Smith | A |
| 1 | Alice | Physics | Dr. Brown | B+ |
| 2 | Bob | Chemistry | Dr. White | A- |
| 3 | Charlie | Math | Dr. Smith | B+ |
| 3 | Charlie | Biology | Dr. Gray | A- |
| 3 | Charlie | Chemistry | Dr. White | A |
Primary Key for 1NF: (S_ID, Course)
S_ID -> S-Name (partial dependency on S_ID)Course -> Instructor (partial dependency on Course)(S_ID, Course) -> Grade (full dependency on the composite key)In 1NF, S-Name and Instructor depend on parts of the composite primary key (S_ID, Course).
To eliminate these partial dependencies, we decompose the table into three relations:
STUDENT
| S_ID | S-Name |
|---|---|
| 1 | Alice |
| 2 | Bob |
| 3 | Charlie |
PK: S_ID
COURSE
| Course | Instructor |
|---|---|
| Math | Dr. Smith |
| Physics | Dr. Brown |
| Chemistry | Dr. White |
| Biology | Dr. Gray |
PK: Course
ENROLLMENT
| S_ID | Course | Grade |
|---|---|---|
| 1 | Math | A |
| 1 | Physics | B+ |
| 2 | Chemistry | A- |
| 3 | Math | B+ |
| 3 | Biology | A- |
| 3 | Chemistry | A |
PK: (S_ID, Course)
All non-prime attributes in these three relations depend fully on their entire candidate keys. Thus, the schema is in 2NF.
A relation in 2NF is in 3NF if no non-prime attribute transitively depends on a candidate key.
STUDENT(S_ID, S-Name), S_ID is the candidate key and determines S-Name. No transitive dependency exists.COURSE(Course, Instructor), Course is the candidate key and determines Instructor. No transitive dependency exists.ENROLLMENT(S_ID, Course, Grade), (S_ID, Course) is the candidate key and determines Grade. No transitive dependency exists.Since there are no transitive dependencies, the 2NF schema is already in 3NF.
Final 3NF Schema: STUDENT(S_ID,S-Name),COURSE(Course,Instructor),ENROLLMENT(S_ID,Course,Grade)Check.
Reconstruction check:
STUDENT on S_ID = 1, ENROLLMENT on Course = 'Math', and COURSE on Course = 'Math'. Result: Alice, Math, Dr. Smith, Grade A. Perfectly matches row 1 of the initial table.Exam tip.
Underline the primary keys in your final relations to make them stand out clearly.
Sources.
Topic: T08.1 · Why normalize: redundancy and insert/update/delete anomalies · Section A · CLO4
Question. What are the anomalies that normalization aims to eliminate? Provide examples of insertion, deletion and update anomalies.
Answer.
What the examiner wants.
Naming the three anomalies (1 mark), followed by clear definitions and concrete examples for each using an employee/department or student/course table (3 marks).
Key idea.
When independent facts share a table, they cannot be modified independently. An insertion requires dummy data, a deletion erases unintended facts, and an update requires touchpoints across many records.
Step-by-step solution.
Normalization aims to eliminate three modification anomalies caused by data redundancy and undesirable functional dependencies:
EMP_DEPTConsider an unnormalized table where employee and department facts share one relation:
| Emp_ID | Emp_Name | Dept_ID | Dept_Name | Location |
|---|---|---|---|---|
| E01 | Alice | D10 | IT | Building A |
| E02 | Bob | D20 | HR | Building B |
| E03 | Charlie | D10 | IT | Building A |
Primary Key: Emp_ID
D30 (Finance, Building C). Because Emp_ID is the primary key, it cannot be NULL. We cannot record department D30 until an employee is hired.E02 is the only person working in department D20 (HR). If Bob resigns and we delete his row (E02), the fact that department D20 is HR located in Building B is permanently erased.D10) moves to "Building D", we must update both rows E01 and E03. If the system updates E01 but fails on E03, department D10 has two conflicting locations.Check.
Quick self-test:
Emp_ID?EMP_DEPT into EMPLOYEE(Emp_ID, Emp_Name, Dept_ID) and DEPARTMENT(Dept_ID, Dept_Name, Location).Exam tip.
Stick to the standard EMP_DEPT or STUDENT_COURSE table. It keeps your answer compact and lets you show all three anomalies on the same data.
Sources.
Topic: T05.2 · DDL + DML warm-up: CREATE, INSERT, ALTER ... ADD, UPDATE, DELETE, rename, filter · Section A · CLO2
Question.
Write SQL queries for the following:
(i) Create a table "Employee" with attributes: EmpID (primary key), Name, Age and Department.
(ii) Insert a record into this table: EmpID=1, Name='Nafisa', Age=21, department='HR'.
(iii) Find employees whose salary is greater than the average salary of their department.
Answer.
What the examiner wants.
Three progressive SQL queries (2 marks each):
CREATE TABLE with primary key declaration.INSERT INTO statement with literal values.Key idea.
Part (iii) requires comparing each employee's salary to an aggregate computed over a specific group (their own department). Because the inner aggregate depends on the department of the current outer tuple (e1.Department = e2.Department), the query must be structured as a correlated subquery.
Step-by-step solution.
(i) Create table Employee:
CREATE TABLE Employee (
EmpID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
Department VARCHAR(30)
);
(ii) Insert record into Employee:
INSERT INTO Employee (EmpID, Name, Age, Department)
VALUES (1, 'Nafisa', 21, 'HR');
(iii) Find employees earning more than their department's average salary:
Assumption: The Employee relation includes an attribute Salary DECIMAL(10,2).
SELECT *
FROM Employee e1
WHERE e1.Salary > (
SELECT AVG(e2.Salary)
FROM Employee e2
WHERE e2.Department = e1.Department
);
Check.
Trace of correlated execution:
e1 in the 'HR' department earning 40,000:
The inner query computes AVG(Salary) for all employees where Department = 'HR'.
If the HR average is 32,000, 40000 > 32000 evaluates to true, and e1 is included in the output.Exam tip.
When an attribute requested by a query is missing from the problem's own schema definition, declare an assumption line immediately.
Sources.
Deck 03 · Slides 7, 52, 56, Textbook Ch. 3 §3.2, §3.8.
Topic: T03.2 · Keys: super / candidate / primary / alternate / composite / foreign · Section A · CLO2
Question.
Explain the distinctions among the terms-
(i) Primary key
(ii) Candidate key
(iii) Super key
(iv) Composite key
Answer.
What the examiner wants.
Precise definitions and clear distinctions among the four key types. The mark split is 1 mark per key type. The examiner expects minimality rules, nullability constraints, and an illustrative relational table.
Key idea.
Think of a super key as any attribute set that uniquely identifies a row. A candidate key is a minimal super key: removing any attribute ruins uniqueness. The primary key is the single candidate key chosen by the database designer. A composite key is any key consisting of two or more attributes.
Step-by-step solution.
A key is an attribute or set of attributes used to identify rows in a table.
Distinctions Among Keys:
| Key Type | Definition | Minimality | NULL Allowed |
|---|---|---|---|
| (i) Primary Key | The candidate key chosen by the database designer to identify tuples uniquely. | Yes (minimal) | No (never allowed) |
| (ii) Candidate Key | A minimal super key. Removing any attribute destroys uniqueness. | Yes (strictly minimal) | Yes (unless constrained NOT NULL) |
| (iii) Super Key | Any set of attributes that uniquely identifies a row. May contain extra attributes. | No (can have redundant attributes) | No for identifying columns |
| (iv) Composite Key | A key that consists of two or more attributes rather than a single attribute. | Can be minimal (candidate) or non-minimal | Depends on whether it is PK or unique |
Relationship:
Primary Key⊆Candidate Keys⊆Super KeysRunning Example:
Consider relation Student(student_id,name,email,nid,dept_name):
| student_id | name | nid | dept_name | |
|---|---|---|---|---|
| 101 | Akib | akib@gmail.com | 1999123456 | ECE |
| 102 | Shuvo | shuvo@gmail.com | 2000654321 | ECE |
| 103 | Sakib | sakib@gmail.com | 2001987654 | ETE |
Short version for 2018 Q.2(a) (4 marks): Omit (iv) Composite key. Keep the definitions, distinctions table, and the Student running example for Super Key, Candidate Key, and Primary Key.
Short version for 2021 Q.2(b) (3 marks): Same as 2018 Q.2(a). Present the 3-row distinction table and the Student relation key classification.
Check.
Minimality and closure verification:
name) and cannot be a candidate key.Exam tip.
Write down the subset formula Primary Key⊆Candidate Keys⊆Super Keys right above your example. This gives the examiner an instant visual proof of your grasp.
Sources.
Topic: T12.4 · RAID levels, comparison, and recovery role · Section A · CLO1
Question. Discuss the features of RAID models.
Answer.
What the examiner wants.
A discussion of the core architectural capabilities of RAID: parallel striping, redundancy mechanisms, transparent virtualization, hot swapping/rebuilds, and data scrubbing.
Key idea.
RAID is more than disk duplication. It combines parallel bus performance, mathematical error correction, virtualized storage abstractions, and proactive hardware maintenance.
Step-by-step solution.
A Redundant Array of Independent Disks (RAID) provides four major architectural features:
Check.
Quick self-test:
Exam tip.
Group your points by feature titles: Striping, Redundancy, Virtualization, Hot Swapping, and Scrubbing.
Sources.
Topic: T09.1 · ACID properties · Section A · CLO3
Question. Briefly explain the importance of ACID properties of transactions with suitable example.
Answer.
What the examiner wants.
The technical justification for why each ACID property is critical in a database system. The examiner expects an example (typically fund transfer) and concrete failure scenarios showing what disaster occurs if any single property is missing. Mark split: 1 mark per property.
Key idea.
Do not merely define the terms. Explain the failure consequence of omitting each property: lost money for atomicity, corrupted business rules for consistency, phantom dirty reads for isolation, and wiped transactions for durability.
Step-by-step solution.
Databases must handle two critical challenges: system failures (crashes, power loss) and concurrent user execution. The ACID properties are essential because without them, database data becomes corrupt and untrustworthy.
Example: Transaction T1 transfers $50 from account A ($1000) to account B ($2000). The invariant is A+B=3000.
Importance of Each Property:
Importance of Atomicity:
Importance of Consistency:
Importance of Isolation:
Importance of Durability:
Check.
Quick self-test:
Exam tip.
Structure each property as a two-part bullet: Failure case without property followed by Protection provided. This layout proves you understand the importance of the concept.
Sources.
Topic: T09.3 · Transaction states / life-cycle diagram · Section A · CLO3
Question. Draw state diagram of a transaction.
Answer.
What the examiner wants.
A clean, correct state diagram showing the five lifecycle states (Active, Partially Committed, Failed, Aborted, Committed) with accurate directional arrows.
Key idea.
Represent the state machine clearly. Show how Active leads to Partially Committed on success, or Failed on error, and how Partially Committed leads to Committed or Failed.
Step-by-step solution.
Figure: Transaction State Diagram (Source: Deck 07, Slide 8)
State Transitions:
Check.
Quick self-test:
Exam tip.
In a 2-mark drawing question, keep your text minimal. Draw the diagram with clear state labels and directional arrows, then add a 1-line legend of transitions.
Sources.
Topic: T06.4 · Views and CREATE VIEW · Section B · CLO2
Question. What are the benefits of VIEW?
Answer.
What the examiner wants.
A concise definition of what a view is, followed by four clear benefits of using views in database systems (about 0.75 marks per benefit).
Key idea.
A view is a saved query that acts like a virtual table. It does not duplicate table data on disk. Instead, it creates a custom window into the database. It improves security by hiding columns, simplifies complex SQL, and gives logical data independence.
Step-by-step solution.
A view is a virtual relation defined by an SQL query. The database does not store the view data on disk. Instead, it stores the query definition and executes it when referenced.
Key Benefits of Views:
SELECT queries on the view.Check.
Quick self-test:
Exam tip.
Include a concrete security example, such as hiding instructor salaries from students. This convinces the examiner immediately.
Sources.
Topic: T06.4 · Views and CREATE VIEW · Section B · CLO2
Question.
Create a VIEW using SQL query that shows the EmployeeName, DepartmentName and salary for employees who earn a salary of more than 55,000.
E.
| EmployeeID | EmployeeName | Department ID |
|---|---|---|
| 101 | Jhon | D01 |
| 102 | Jane | D02 |
| 103 | Alice | D01 |
| 104 | Bob | D03 |
| DepartmentID | DepartmentName |
|---|---|
| D01 | Sales |
| D02 | HR |
| D03 | IT |
| EmployeeID | Salary |
|---|---|
| 101 | 50,000 |
| 102 | 60,000 |
| 103 | 55,000 |
| 104 | 70,000 |
Answer.
What the examiner wants.
Accurate SQL DDL using CREATE VIEW view_name AS SELECT ... that joins tables to retrieve EmployeeName, DepartmentName, and Salary, filtered by Salary > 55000 (2 marks for syntax and joins, 1 mark for the filter).
Key idea.
The query joins relations on matching keys (DeptID or DepartmentID and EmployeeID), projects the required three attributes, and filters rows where Salary > 55000.
Step-by-step solution.
Assumption: Schema consists of Employee(EmpID, EmployeeName, Salary, DeptID) and Department(DeptID, DepartmentName).
SQL Query (Standard 2-Table Schema):
CREATE VIEW High_Salary_Employees AS
SELECT Employee.EmployeeName, Department.DepartmentName, Employee.Salary
FROM Employee
JOIN Department ON Employee.DeptID = Department.DeptID
WHERE Employee.Salary > 55000;
Alternative SQL Query (Using Printed Tables E, D, and S): Joining table E, table D, and table S:
CREATE VIEW High_Salary_Employees AS
SELECT E.EmployeeName, D.DepartmentName, S.Salary
FROM E
JOIN D ON E.`Department ID` = D.DepartmentID
JOIN S ON E.EmployeeID = S.EmployeeID
WHERE S.Salary > 55000;
View Output:
| EmployeeName | DepartmentName | Salary |
|---|---|---|
| Jane | HR | 60,000 |
| Bob | IT | 70,000 |
(Note: Employees Jhon with 50,000 and Alice with 55,000 are excluded because their salaries do not exceed 55,000).
Check.
Tuple-by-tuple trace on printed data:
50000 > 55000 is False. Excluded.60000 > 55000 is True. Included: (Jane, HR, 60,000).55000 > 55000 is False. Excluded because the condition is strictly greater than.70000 > 55000 is True. Included: (Bob, IT, 70,000).Exam tip.
State an explicit schema assumption if the question wording does not specify table structure. Also show the resulting tuples to verify the query output.
Sources.
Topic: T06.1 · Types of joins · Section B · CLO2 (Repeated question: Also asked in 2019 | Solved in T06)
Question. Define joining. Discuss different types of joining with suitable example.
Answer.
What the examiner wants.
A formal definition of a join operation in relational database systems (1 mark), followed by descriptions and examples of the main join types: Inner join, Left outer join, Right outer join, Full outer join, and Cross join (4 marks, approximately 1 mark per join type).
Key idea.
A join operation combines tuples from two tables into a single result relation. It checks matching values in specified columns. An inner join keeps only matching rows. An outer join retains matching rows plus unmatched rows from one or both tables by padding empty attributes with NULL. A cross join pairs every row from the first table with every row from the second table.
Step-by-step solution.
Definition of Joining:
A join operation takes two relations and combines them into one relation based on a matching condition. It acts as a Cartesian product followed by a selection predicate and projection.
Figure: Join types and join conditions (Deck 04, Slide 4)
Example Base Tables:
Table course:
| course_id | title | dept_name | credits |
|---|---|---|---|
| BIO-301 | Genetics | Biology | 4 |
| CS-190 | Game Design | Comp. Sci. | 4 |
| CS-315 | Robotics | Comp. Sci. | 3 |
Table prereq:
| course_id | prereq_id |
|---|---|
| BIO-301 | BIO-101 |
| CS-190 | CS-101 |
| CS-347 | CS-101 |
Retains only tuples that satisfy the join condition in both tables. Unmatched rows are dropped.
SELECT course.course_id, title, dept_name, prereq_id
FROM course
INNER JOIN prereq ON course.course_id = prereq.course_id;
Relational algebra:
course⋈prereqResult:
| course_id | title | dept_name | prereq_id |
|---|---|---|---|
| BIO-301 | Genetics | Biology | BIO-101 |
| CS-190 | Game Design | Comp. Sci. | CS-101 |
Preserves every row from the left table (course). Fills right-table attributes with NULL when no match exists.
SELECT course.course_id, title, dept_name, prereq_id
FROM course
LEFT JOIN prereq ON course.course_id = prereq.course_id;
Relational algebra:
course⟕prereqResult:
| course_id | title | dept_name | prereq_id |
|---|---|---|---|
| BIO-301 | Genetics | Biology | BIO-101 |
| CS-190 | Game Design | Comp. Sci. | CS-101 |
| CS-315 | Robotics | Comp. Sci. | NULL |
Preserves every row from the right table (prereq). Fills left-table attributes with NULL when no match exists.
SELECT prereq.course_id, title, dept_name, prereq_id
FROM course
RIGHT JOIN prereq ON course.course_id = prereq.course_id;
Relational algebra:
course⟖prereqResult:
| course_id | title | dept_name | prereq_id |
|---|---|---|---|
| BIO-301 | Genetics | Biology | BIO-101 |
| CS-190 | Game Design | Comp. Sci. | CS-101 |
| CS-347 | NULL | NULL | CS-101 |
Retains all rows from both tables. It pairs matching rows and fills missing values with NULL. MySQL emulates it using UNION.
SELECT course.course_id, title, dept_name, prereq_id
FROM course
LEFT JOIN prereq ON course.course_id = prereq.course_id
UNION
SELECT prereq.course_id, title, dept_name, prereq_id
FROM course
RIGHT JOIN prereq ON course.course_id = prereq.course_id;
Relational algebra:
course⟗prereqResult:
| course_id | title | dept_name | prereq_id |
|---|---|---|---|
| BIO-301 | Genetics | Biology | BIO-101 |
| CS-190 | Game Design | Comp. Sci. | CS-101 |
| CS-315 | Robotics | Comp. Sci. | NULL |
| CS-347 | NULL | NULL | CS-101 |
Combines each row of the first table with every row of the second table without any condition.
SELECT *
FROM course
CROSS JOIN prereq;
Relational algebra:
course×prereqIt returns 3×3=9 rows.
Variant for 2023 Q.5(c) (4 marks): The same definition and four outer and inner join examples answer the question.
Check.
Quick self-test:
prereq.NULL.FULL OUTER JOIN syntax directly?FULL OUTER JOIN syntax, so we combine LEFT JOIN and RIGHT JOIN with UNION.Exam tip.
Use one small pair of 3-row tables across all join types. This saves drawing time and lets the examiner verify row counts instantly.
Sources.
Topic: T05.9 · TRUNCATE vs DELETE · Section B · CLO2
Question. What is the difference between 'Truncate' and 'Delete' in SQL?
Answer.
What the examiner wants.
Direct architectural and operational comparison between TRUNCATE and DELETE in SQL (especially in MySQL), addressing command category (DDL vs DML), filtering capability, rollback/transaction semantics, triggers, auto-increment counter handling, and performance.
Key idea.
DELETE is a row-level DML statement that individually removes tuples, checks constraints, fires triggers, and writes extensive undo logs for each deleted row. TRUNCATE is a table-level DDL statement that drops and recreates the data storage pages directly, bypassing row-level trigger logic and running substantially faster with minimal logging.
Step-by-step solution.
Both TRUNCATE and DELETE remove rows from a relation, but they operate at different architectural levels:
| Feature | TRUNCATE TABLE | DELETE FROM |
|---|---|---|
| Command Category | DDL (Data Definition Language) | DML (Data Manipulation Language) |
Row Filtering (WHERE) | Not supported; always empties the entire table | Supported; deletes specific filtered rows or all rows |
| Transaction & Rollback | Executes an implicit COMMIT in MySQL; cannot be rolled back | Logged row-by-row; can be rolled back inside a transaction |
| Triggers | Does not fire DELETE triggers | Fires BEFORE DELETE and AFTER DELETE triggers for each row |
AUTO_INCREMENT Counter | Resets the auto-increment counter back to its starting value (1) | Preserves the current auto-increment counter sequence |
| Execution Speed | Extremely fast; deallocates data pages directly | Slower; scans rows and records individual undo/redo logs |
Check.
Quick self-test:
TRUNCATE TABLE student WHERE dept = 'ECE'?TRUNCATE has no WHERE clause; attempting to provide one causes a syntax error.DELETE FROM table, what will the next inserted row's ID be?TRUNCATE TABLE were used instead, it would reset to 1.Exam tip.
A concise 6-row comparison table is the fastest, cleanest way to secure full 2/2 marks on this question.
Sources.
Textbook Ch. 3 §3.9, MySQL 8.0 Reference Manual (§13.1.37 TRUNCATE TABLE, §13.2.2 DELETE).
Topic: T07.3 · Implement a trigger or stored procedure · Section B · CLO2
Question.
Considering the tables (Products, Orders, and Auditlog) answer (i) and (ii).
(i) Create a stored procedure to place an order consider stock availability, updates the stock.
(ii) Create a trigger to log every stock update in the Auditlog table automatically.
Answer.
What the examiner wants.
Implementation of two distinct database routines: a stored procedure that checks stock availability and places an order within a safe transaction (3 marks), and an automatic AFTER UPDATE trigger that logs every inventory change into an audit table (3 marks).
Key idea.
The stored procedure coordinates the ordering workflow: it locks the item row, checks whether enough units exist, creates the order record, and reduces inventory. The trigger acts as an automatic observer: whenever product stock changes for any reason, it automatically writes a historical log entry.
Step-by-step solution.
Assumption: The table schemas are Products(product_id, name, stock, price), Orders(order_id, product_id, quantity, order_date), and Auditlog(log_id, product_id, old_stock, new_stock, changed_at).
The stored procedure verifies available stock using row-level locking (FOR UPDATE), places the order, and reduces the inventory within a transaction:
DELIMITER //
CREATE PROCEDURE PlaceOrder (
IN p_product_id INT,
IN p_quantity INT
)
BEGIN
DECLARE v_stock INT;
START TRANSACTION;
-- Lock the target product row to prevent concurrent race conditions
SELECT stock INTO v_stock
FROM Products
WHERE product_id = p_product_id
FOR UPDATE;
-- Validate product existence and stock sufficiency
IF v_stock IS NULL THEN
ROLLBACK;
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Error: Product does not exist';
ELSEIF v_stock < p_quantity THEN
ROLLBACK;
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Error: Insufficient stock available';
ELSE
-- Record the new order
INSERT INTO Orders (product_id, quantity, order_date)
VALUES (p_product_id, p_quantity, NOW());
-- Deduct ordered quantity from stock
UPDATE Products
SET stock = stock - p_quantity
WHERE product_id = p_product_id;
COMMIT;
END IF;
END //
DELIMITER ;
An AFTER UPDATE trigger detects when the stock column changes and writes an audit record to Auditlog:
DELIMITER //
CREATE TRIGGER trg_log_stock_update
AFTER UPDATE ON Products
FOR EACH ROW
BEGIN
-- Log only when the stock quantity actually changes
IF OLD.stock <> NEW.stock THEN
INSERT INTO Auditlog (product_id, old_stock, new_stock, changed_at)
VALUES (OLD.product_id, OLD.stock, NEW.stock, NOW());
END IF;
END //
DELIMITER ;
Check.
Trace with concrete sample tuples:
Products(101, 'Monitor', 10, 150.00).CALL PlaceOrder(101, 3);.
Orders(order_id, 101, 3, NOW()).Products setting stock = 10 - 3 = 7.Products automatically fires trg_log_stock_update. Since OLD.stock(10)=NEW.stock(7), it inserts (101, 10, 7, NOW()) into Auditlog.CALL PlaceOrder(101, 20);.SIGNAL SQLSTATE '45000'. No order is inserted and stock stays at 7.Exam tip.
Always state an explicit schema assumption line right at the start when schemas are omitted in the question. Use distinct prefixes like p_ for parameters and v_ for local variables to prevent naming clashes with column names.
Sources.
Topic: T05.8 · Short notes: ON DELETE CASCADE, GROUP BY, ORDER BY, AS · Section B · CLO2 (Repeated question: Also asked in 2024 | Solved in T05)
Question. Write short note on " ON CASCADE DELETE".
Answer.
What the examiner wants.
Concise technical descriptions, purpose, and standard SQL syntax/examples for four fundamental SQL clauses and constraint actions (1 mark each).
Key idea.
Each term serves a distinct role in relational data management: ON DELETE CASCADE governs referential integrity maintenance; GROUP BY partitions data for summary aggregation; ORDER BY controls output presentation order; AS introduces aliasing for projection expressions and relation names.
Step-by-step solution.
i) ON DELETE CASCADE (printed as "ON CASCADE DELETE"):
A foreign key referential integrity action. When a tuple in the parent table is deleted, the DBMS automatically deletes all corresponding referencing tuples in the child table. This maintains referential integrity and prevents orphaned records.
CREATE TABLE section (
course_id VARCHAR(8),
sec_id VARCHAR(8),
semester VARCHAR(6),
year NUMERIC(4, 0),
PRIMARY KEY (course_id, sec_id, semester, year),
FOREIGN KEY (course_id) REFERENCES course(course_id)
ON DELETE CASCADE
);
ii) GROUP BY:
An SQL clause used to partition table rows into distinct groups having identical values in specified columns. Aggregate functions (COUNT, SUM, AVG, MIN, MAX) then compute summary statistics for each individual group.
SELECT dept_name, AVG(salary) AS avg_sal
FROM instructor
GROUP BY dept_name;
iii) ORDER BY:
An SQL clause that sorts query result rows in ascending (ASC, default) or descending (DESC) order based on one or more attributes. Multiple sort keys break ties sequentially.
SELECT name, salary
FROM instructor
ORDER BY salary DESC, name ASC;
iv) AS:
An SQL keyword used to define an alias (an alternative temporary name). It can rename an attribute or computed expression in the SELECT clause for readability, or rename a table in the FROM clause to shorten table references and enable self-joins.
SELECT salary * 1.15 AS revised_salary
FROM employee AS e;
Short version for 2019 Q.8(c) (4 marks): Provide parts (i) and (ii).
Short version for 2023 Q.6(c) (2 marks): Provide part (i) with definition, syntax, and effect.
Check.
Referential trace of ON DELETE CASCADE:
department.course have dept_name = 'Biology'.department via DELETE FROM department WHERE dept_name = 'Biology' automatically removes the three referencing courses from course.Exam tip.
For short notes on SQL statements, always supply both the formal definition and a minimal code snippet illustrating syntax.
Sources.
Deck 03 · Slides 8, 20, 24, 32, Deck 04 · Slide 4, Textbook Ch. 3 §3.4, §3.6, §3.7, Textbook Ch. 4 §4.4.5.
Topic: T12.1 · Failure classification, precautions, recovery methods · Section B · CLO2 (Repeated question: Also asked in 2017 | Solved in T12)
Question. Explain the different types of failures that can occur in a database system.
Answer.
What the examiner wants.
The three fundamental failure classes in a DBMS: transaction failure, system crash, and disk failure. Examiners look for the affected storage medium and a 1-mark split per class.
Key idea.
Different components fail differently. Main memory is volatile and loses data on power loss. Disk drives are non-volatile and survive power loss, but suffer physical media damage. Transactions can fail internally even when all hardware is operating normally.
Step-by-step solution.
A database management system experiences three main classes of failure based on the affected storage component:
Variant for 2023 Q.7(a) (CLO2, 3 marks): The same three-part classification directly answers the question.
Check.
Quick self-test:
Exam tip.
Structure the answer clearly into three numbered tiers: transaction logic, volatile memory (system crash), and non-volatile disk media.
Sources.
Topic: T12.3 · Log-based recovery and shadow paging · Section B · CLO2
Question. What is log based recovery? Illustrate with an example of a system crash and recovery process.
Answer.
What the examiner wants.
A formal definition of log-based recovery followed by a complete worked crash scenario showing the log state at crash, the classification into redo and undo lists, the recovery actions, and the final data values.
Key idea.
Recovery replays history forward from the log to restore updates of committed transactions, then scans backward to erase updates of active transactions that never completed.
Step-by-step solution.
Log-based recovery is a crash recovery technique that records all database update actions on stable storage in a sequential log prior to updating the database on disk. By maintaining both old and new values, the recovery manager can undo incomplete transactions and redo committed transactions after a failure.
Consider three transactions running on data items A, B, and C with initial values A=1000, B=2000, and C=500:
State of Log on Stable Storage at Crash:
1. <T1 start>
2. <T1, A, 1000, 900>
3. <T1, B, 2000, 2100>
4. <T1 commit>
5. <T2 start>
6. <T2, C, 500, 700>
7. <T3 start>
8. <T2 commit>
9. <T3, B, 2100, 2050>
---- CRASH OCCURS HERE ----
<start> and <commit> records).<start> but no <commit> or <abort> record).Final Database State: A=900, B=2100, C=700. Both atomicity for T3 and durability for T1 and T2 are satisfied.
Check.
Trace verification:
Exam tip.
Write out a clean, numbered log sequence. Then explicitly display the Redo-list and Undo-list before detailing the value changes.
Sources.
Topic: T12.4 · RAID levels, comparison, and recovery role · Section B · CLO2
Question. Briefly describe the RAID model and its significance in database recovery.
Answer.
What the examiner wants.
A two-part response: a concise definition of the RAID model, followed by its specific significance in database recovery (realizing stable storage, preventing offline tape restores, protecting transaction logs).
Key idea.
Database recovery algorithms theoretically depend on stable storage. RAID provides the practical hardware foundation that keeps data and write-ahead logs durable against physical media loss.
Step-by-step solution.
The RAID (Redundant Array of Independent Disks) model combines multiple physical disk drives into a single logical unit. It uses data striping for parallel speed and data redundancy (mirroring or parity) for reliability.
Check.
Quick self-test:
Exam tip.
Explicitly mention stable storage and explain how RAID eliminates the need for slow offline tape restoration.
Sources.
Topic: T13.3 · Indexing: dense vs sparse index · Section B · CLO1
Question. Write short note on dense and sparse index.
Answer.
What the examiner wants.
Concise definitions of dense and sparse indices (1 mark) and their key differences in lookup speed, storage overhead, and file ordering requirements (1 mark).
Key idea.
An index speeds up search by mapping search keys to disk block locations. A dense index is like an index at the back of a textbook with an entry for every term. A sparse index is like the header word at the top of a dictionary page, pointing only to the start of each page.
Step-by-step solution.
1. Definitions
Figure 13.1: Dense index on instructor file with search key ID (Source: Textbook Ch. 14, Fig. 14.2).
Figure 13.2: Sparse index on instructor file with search key ID (Source: Textbook Ch. 14, Fig. 14.3).
2. Comparison
| Feature | Dense Index | Sparse Index |
|---|---|---|
| Index Entries | One entry for every search-key value in the file. | One entry for only some search-key values (usually one per disk block). |
| Lookup Speed | Faster. Locates the exact record or its list of duplicates directly. | Slower. Requires an index lookup followed by a sequential block scan. |
| Space Overhead | Large. The index file consumes significant disk or memory space. | Small. The index file is much smaller and often fits in main memory. |
| File Ordering | Can be built on sorted (clustering) or unsorted (non-clustering) files. | Requires the data file to be ordered on the search key (clustering only). |
| Maintenance Cost | High. Insertions and deletions often require adding or removing index entries. | Low. Records can often be inserted or deleted inside a block without updating the index. |
Practical Trade-off: A sparse index with one entry per disk block offers a good compromise between lookup speed and index size.
Check.
Trace Example (Searching for instructor ID "22222" using Figures 13.1 and 13.2):
22222. The pointer goes straight to record 22222 in disk block 1. Cost: 1 index access + 1 data block access.10101, 32343, and 76543. The largest key ≤22222 is 10101. The pointer goes to block 1. The DBMS scans block 1 sequentially until it finds 22222.Quick self-test:
Exam tip.
For 2 marks, give clear two-line definitions followed by a compact 4-row comparison table.
Sources.
[Textbook Ch. 14 §14.2.1](../Textbook/Chapter_14_Indexing/Chapter%2014%20-%20Indexing.md)
Topic: T10.3 · Precedence-graph test → cycle → serial order(s) · Section B · CLO3
Question.
Check whether the given schedules S is conflict serializeable or not. If yes, then determine all the possible serialized schedules.
| T1 | T2 | T3 | T4 |
|---|---|---|---|
| R(A) | |||
| R(A) | |||
| W(B) | |||
| R(A) | |||
| W(A) | |||
| R(B) | |||
| W(B) |
Answer.
What the examiner wants. Complete list of conflicting pairs (1 mark), drawing the 4-node precedence graph (1 mark), acyclic verdict (0.5 marks), and finding all valid topological sorts (1.5 marks).
Key idea. With 4 transactions, the precedence graph defines a partial order. If the graph has no cycles, it is conflict serializable. Because some transactions have no direct or indirect dependency between them, there may be more than one valid topological sort. The question asks for all possible serialized schedules, so we must find every single one.
Step-by-step solution.
Let the rows of schedule S be indexed 1 to 7:

The directed edges are:
There are no backward edges, so the precedence graph is acyclic.
Verdict: Schedule S is conflict serializable.
We perform topological sorting on the directed acyclic graph:
Therefore, T4 can be placed in any position as long as it appears before T2:
Result: There are exactly 3 possible serialized schedules.
Check.
Exam tip. When asked for "all possible serialized schedules", state the partial ordering constraints first. Then show each position where the unconstrained transaction can fit.
Sources.
Topic: T11.6 · Timestamp ordering: R-TS/W-TS rules, trace a schedule; rolled-back transaction gets a NEW timestamp · Section B · CLO3
Question.
Discuss the given schedule based on Timestamp ordering protocol.
| T1(100) | T2(200) | T3(300) |
|---|---|---|
| R(A) | ||
| R(B) | ||
| W(C) | ||
| R(B) | ||
| R(C) | ||
| W(B) | ||
| W(A) |
Answer.
What the examiner wants.
A step-by-step trace of each read and write operation in the schedule against the Timestamp Ordering (TSO) protocol rules. The trace must track read and write timestamps of items A,B, and C. The examiner looks for the critical conflict at step 6 where T2 attempts W(B) and is rolled back.
Key idea.
Under TSO, operations must look like they ran in timestamp order: T1(100)→T2(200)→T3(300). When T3 reads B, the read timestamp of B jumps to 300. Later, T2 tries to write B. But T2 has timestamp 200, which is less than 300. T2 is trying to write a value that T3 should have seen. So the protocol rejects T2's write and rolls T2 back.
Step-by-step solution.
1. Initial State:
2. Step-by-Step Trace Table:
| Step | Txn | Op | Protocol Rule & Condition Check | Action | Updated Timestamps |
|---|---|---|---|---|---|
| 1 | T1 | R(A) | TS(T1)≥W-TS(A)⟹100≥0 (Valid) | Execute | R-TS(A)=max(0,100)=100 |
| 2 | T2 | R(B) | TS(T2)≥W-TS(B)⟹200≥0 (Valid) | Execute | R-TS(B)=max(0,200)=200 |
| 3 | T1 | W(C) | TS(T1)≥R-TS(C) and W-TS(C)⟹100≥0 (Valid) | Execute | W-TS(C)=100 |
| 4 | T3 | R(B) | TS(T3)≥W-TS(B)⟹300≥0 (Valid) | Execute | R-TS(B)=max(200,300)=300 |
| 5 | T1 | R(C) | TS(T1)≥W-TS(C)⟹100≥100 (Valid) | Execute | R-TS(C)=max(0,100)=100 |
| 6 | T2 | W(B) | TS(T2)<R-TS(B)⟹200<300 (Violated!) | REJECTED | T2 is rolled back |
| 7 | T3 | W(A) | TS(T3)≥R-TS(A) and W-TS(A)⟹300≥100 (Valid) | Execute | W-TS(A)=300 |
3. Detailed Evaluation:
Conclusion:
The schedule is not accepted without rollback. At Step 6, transaction T2 violates timestamp ordering and is rolled back. When restarted, T2 must receive a new timestamp greater than 300.
Check.
Verification of conflict:
Exam tip.
Always draw the step-by-step trace table with columns for Step, Transaction, Operation, Condition Check, Decision, and Updated Timestamps. This structure proves every step to the examiner.
Sources.
← Prev: 2021 | Exam-Style Layer | Original Question Paper | Next: 2024 →