Tribhuvan University
Faculty of Management
Office of the Dean
Official Model Question Paper / Dean's Office Blueprint
Candidates are required to give their answers in their own words as far as practicable. The figures in the margin indicate full marks.
Group A
Brief Answer Questions. Attempt ALL questions.
[5 × 2 = 10]- [2]
Define Data Independence and differentiate between Physical and Logical data independence.
View model solution
Answer: Data Independence: The capacity to modify a database schema at one level without affecting schemas at adjacent higher levels.
- Physical Data Independence: Ability to modify internal/physical storage structures (indexing, file organization) without changing the conceptual schema.
- Logical Data Independence: Ability to modify the conceptual schema (adding columns, tables) without changing external schemas or application views.
- [2]
What are the four ACID properties of a database transaction?
View model solution
Answer:
- Atomicity: All transaction operations succeed completely, or none are applied (‘all-or-nothing’).
- Consistency: A transaction transforms the database from one valid state to another, preserving all integrity constraints.
- Isolation: Concurrent transactions execute without interfering with one another.
- Durability: Once committed, transaction updates persist permanently, surviving system crashes.
- [2]
Differentiate between a Primary Key and a Foreign Key.
View model solution
Answer:
- Primary Key: A candidate key chosen to uniquely identify every tuple in a relation; cannot contain null values.
- Foreign Key: An attribute (or set of attributes) in one relation that matches the primary key of another relation, enforcing referential integrity between tables.
- [2]
Define a Weak Entity in an Entity-Relationship (ER) model and explain how it is identified.
View model solution
Answer: Weak Entity: An entity that does not possess sufficient attributes to form its own primary key and depends on the existence of an identifying strong entity. Identification: Identified by combining the primary key of its identifying strong entity with its own partial key (discriminator) via an identifying relationship.
- [2]
What is a Database Deadlock? Name one technique to prevent deadlocks.
View model solution
Answer: Deadlock: A condition where two or more concurrent transactions are in a state of indefinite waiting because each holds a lock on a data item that another transaction requires. Prevention Technique: Wait-Die or Wound-Wait timestamp-based ordering schemes.
Group B
Descriptive Answer Questions. Attempt any THREE questions.
[3 × 10 = 30]- [10]
Explain the Three-Schema Database Architecture (ANSI/SPARC). How does it achieve data abstraction and insulate applications from physical data restructuring?
View model solution
ANSI/SPARC Three-Schema Database Architecture
1. The Three Schema Levels
The architecture separates the database into three abstraction layers:
-
Internal (Physical) Level:
- Closest to physical hardware storage.
- Describes how data is physically stored on disk: data structures, record formats, B+ tree indexes, compression algorithms, and access paths.
- Managed by database systems programmers and DBAs.
-
Conceptual (Logical) Level:
- Represents the global view of the entire database for the entire organization.
- Defines entities, data types, relationships, constraints, and business rules without regard to physical storage.
- Defined using DDL by database designers.
-
External (View) Level:
- Closest to end users.
- Consists of multiple external schemas (views) tailored to specific user groups (e.g., HR view, Sales view, Student view).
- Hides irrelevant or sensitive data (e.g., employee salaries hidden from departmental coworkers).
2. Mappings and Data Independence
- External-Conceptual Mapping: Maps external views to the global conceptual schema. Provides Logical Data Independence—the conceptual schema can be modified (e.g., adding an optional column) without altering existing application views.
- Conceptual-Internal Mapping: Maps conceptual relations to physical disk blocks and file indexes. Provides Physical Data Independence—the storage subsystem can be migrated from HDD to NVMe SSD or index re-built without altering the logical schema or user SQL queries.
-
- [10]
Given the following relational schema for a university management system:
Student(StudentID, Name, Major, GPA)Course(CourseID, Title, Credits, Department)Enrollment(StudentID, CourseID, Semester, Grade)
Write SQL queries for: a) Retrieve names and GPAs of students majoring in ‘Management’ with GPA > 3.5. b) Find the total number of students enrolled in each course for the ‘Fall 2024’ semester. c) List titles of courses that have never had any student enrollment. d) Increase credits by 1 for all courses offered by the ‘Computer Science’ department.
View model solution
SQL Queries for University Schema
a) Students majoring in ‘Management’ with GPA > 3.5:
SELECT Name, GPA FROM Student WHERE Major = 'Management' AND GPA > 3.5;
b) Total students enrolled in each course for ‘Fall 2024’:
SELECT C.CourseID, C.Title, COUNT(E.StudentID) AS TotalEnrolled FROM Course C LEFT JOIN Enrollment E ON C.CourseID = E.CourseID AND E.Semester = 'Fall 2024' GROUP BY C.CourseID, C.Title;
c) Courses with zero student enrollments:
-- Using NOT EXISTS: SELECT Title FROM Course C WHERE NOT EXISTS ( SELECT 1 FROM Enrollment E WHERE E.CourseID = C.CourseID ); -- Alternative using LEFT JOIN: SELECT C.Title FROM Course C LEFT JOIN Enrollment E ON C.CourseID = E.CourseID WHERE E.StudentID IS NULL;
d) Update credits by +1 for ‘Computer Science’ courses:
UPDATE Course SET Credits = Credits + 1 WHERE Department = 'Computer Science'; - [10]
Explain Boyce-Codd Normal Form (BCNF). How does BCNF differ from 3NF? Provide a relation that satisfies 3NF but violates BCNF, and demonstrate its lossless decomposition.
View model solution
Boyce-Codd Normal Form (BCNF) vs. Third Normal Form (3NF)
1. Definitions
- 3NF Definition: A relation
is in 3NF if for every functional dependency : is a trivial dependency ( ), OR is a superkey of , OR - Each attribute in
is a prime attribute (part of some candidate key).
- BCNF Definition: A relation
is in BCNF if for every non-trivial functional dependency , must be a superkey of . (BCNF eliminates the prime attribute exception of 3NF).
2. Illustrative Example: 3NF Satisfied but BCNF Violated
Consider relation
with rules: - A student takes multiple subjects, each taught by a specific teacher:
. - Each teacher teaches only one subject:
. - A subject may have multiple teachers.
- Candidate Keys:
and . - Prime Attributes:
.
Check 3NF:
- For
: LHS is a superkey (Satisfies). - For
: LHS is not a superkey, but RHS ( ) is a prime attribute! Thus, the relation is in 3NF.
Check BCNF:
- In
, is NOT a superkey. - Therefore, the relation violates BCNF. (Anomaly: We cannot record which teacher teaches a subject until a student enrolls).
3. Lossless Decomposition into BCNF
Decompose
into two relations: with FD: . (Teacher is a superkey; in BCNF). with composite key . (In BCNF).
The decomposition is lossless (
, which is a key for ), eliminating redundancy. - 3NF Definition: A relation
- [10]
Analyze the Two-Phase Locking (2PL) protocol for concurrency control. Differentiate between Strict 2PL and Rigorous 2PL, and explain how 2PL guarantees serializability.
View model solution
Concurrency Control: Two-Phase Locking (2PL) Protocol
1. Core Principles of 2PL
The Two-Phase Locking protocol ensures conflict serializability by constraining when a transaction can acquire and release locks:
- Phase 1: Growing Phase (Lock Acquisition): A transaction may acquire locks (shared or exclusive) but cannot release any lock.
- Phase 2: Shrinking Phase (Lock Release): A transaction may release locks, but once it releases any lock, it can never acquire any new lock.
- Lock Point: The moment when the transaction holds its maximum number of locks (end of Growing Phase). The ordering of lock points determines the equivalent serial schedule.
2. Variants of 2PL
- Basic 2PL:
- Locks are released gradually during the shrinking phase before transaction commit.
- Problem: Vulnerable to cascading aborts (if transaction
modifies item , releases lock, and then aborts, any that read must also abort).
- Strict 2PL:
- Mandates that all exclusive (write) locks must be held until the transaction explicitly commits or aborts.
- Prevents cascading aborts and guarantees strict schedules.
- Rigorous (Strong Strict) 2PL:
- Mandates that all locks (both shared read locks and exclusive write locks) must be held until the transaction terminates (commit/abort).
- Guarantees that transactions serialize in the exact order in which they commit.
3. Proof that 2PL Guarantees Conflict Serializability
If a schedule produced by 2PL were non-serializable, its precedence graph would contain a cycle (
). An edge implies accessed a data item before , meaning released a lock before acquired it. A cycle would require to release a lock before acquiring another lock, directly violating the 2PL rule that no locks can be acquired after any lock is released.
Group C
Comprehensive Answer / Case Analysis Question. Attempt ALL questions.
[1 × 20 = 20]- [20]
Database Design Case Study: Ride-Hailing Platform Architecture and Concurrency Management
‘YatriRide’ is a fast-growing on-demand ride-hailing and logistics platform in Nepal connecting 20,000 active drivers with 300,000 urban passengers across Kathmandu, Pokhara, and Chitwan:
- Core Entities & Business Rules:
- Each Passenger registers with
PassengerID,FullName,PhoneNumber(unique),Email, andWalletBalance. - Each Driver has
DriverID,FullName,LicenseNumber,Phone,Rating, andStatus(‘Available’, ‘OnTrip’, ‘Offline’). - Each Vehicle has
VehicleID,RegistrationNumber(unique),MakeModel,Category(‘Bike’, ‘Car’, ‘EV-Van’), and is assigned to exactly one Driver. - A Trip is booked by one Passenger and accepted by one Driver, recording
TripID,PickupLocation,DropLocation,FareAmount,TripStatus(‘Requested’, ‘Accepted’, ‘Completed’, ‘Cancelled’), and timestamps. - A Payment transaction records
PaymentID,TripID,PaymentMethod(‘eSewa’, ‘Khalti’, ‘Cash’, ‘Wallet’),Amount, andPaymentTime.
- Each Passenger registers with
- High-Concurrency Challenges: During morning rush hours (8:30 AM - 10:30 AM), multiple passenger ride requests trigger simultaneous database transactions. Under heavy load, two drivers occasionally accepted the exact same ride request simultaneously (‘double-booking anomaly’), causing system errors. Additionally, wallet top-up transactions experienced dirty reads during unexpected network timeouts.
Questions: a) Draw a comprehensive Entity-Relationship (ER) Diagram using Crow’s Foot notation detailing all entities, primary/foreign keys, attributes, and relationship cardinalities. (8 Marks) b) Convert the ER design into a fully normalized Relational Database Schema (3NF) with explicit table definitions, primary keys, and foreign key constraints. (6 Marks) c) Diagnose the technical cause of the ‘double-booking anomaly’. Write an atomic SQL transaction with appropriate locking mechanisms (e.g.,
SELECT ... FOR UPDATE) to prevent concurrent driver acceptance collisions. (6 Marks)View model solution
Comprehensive Database Case Solution: YatriRide Platform
a) Conceptual ER Diagram & Cardinality Specifications
- Entities & Cardinalities:
Passenger(1) —— (0..N)Trip[One passenger books zero or many trips; each trip belongs to exactly one passenger]Driver(1) —— (1)Vehicle[Each driver is registered with exactly one vehicle]Driver(1) —— (0..N)Trip[One driver completes zero or many trips; each accepted trip is assigned to one driver]Trip(1) —— (1)Payment[Each completed trip has exactly one associated payment record]
b) Normalized Relational Database Schema (3NF)
-
PassengerTable:PassengerIDINT PRIMARY KEY AUTO_INCREMENTFullNameVARCHAR(100) NOT NULLPhoneNumberVARCHAR(15) UNIQUE NOT NULLEmailVARCHAR(100)WalletBalanceDECIMAL(10, 2) DEFAULT 0.00 CHECK (WalletBalance >= 0)
-
DriverTable:DriverIDINT PRIMARY KEY AUTO_INCREMENTFullNameVARCHAR(100) NOT NULLLicenseNumberVARCHAR(50) UNIQUE NOT NULLPhoneVARCHAR(15) UNIQUE NOT NULLRatingDECIMAL(3, 2) DEFAULT 5.00StatusENUM(‘Available’, ‘OnTrip’, ‘Offline’) DEFAULT ‘Offline’
-
VehicleTable:VehicleIDINT PRIMARY KEY AUTO_INCREMENTDriverIDINT UNIQUE NOT NULL, FOREIGN KEY (DriverID) REFERENCESDriver(DriverID)RegistrationNumberVARCHAR(30) UNIQUE NOT NULLMakeModelVARCHAR(100) NOT NULLCategoryENUM(‘Bike’, ‘Car’, ‘EV-Van’) NOT NULL
-
TripTable:TripIDBIGINT PRIMARY KEY AUTO_INCREMENTPassengerIDINT NOT NULL, FOREIGN KEY (PassengerID) REFERENCESPassenger(PassengerID)DriverIDINT NULL, FOREIGN KEY (DriverID) REFERENCESDriver(DriverID)PickupLocationVARCHAR(255) NOT NULLDropLocationVARCHAR(255) NOT NULLFareAmountDECIMAL(10, 2) NOT NULLTripStatusENUM(‘Requested’, ‘Accepted’, ‘Completed’, ‘Cancelled’) DEFAULT ‘Requested’CreatedAtTIMESTAMP DEFAULT CURRENT_TIMESTAMP
-
PaymentTable:PaymentIDBIGINT PRIMARY KEY AUTO_INCREMENTTripIDBIGINT UNIQUE NOT NULL, FOREIGN KEY (TripID) REFERENCESTrip(TripID)PaymentMethodENUM(‘eSewa’, ‘Khalti’, ‘Cash’, ‘Wallet’) NOT NULLAmountDECIMAL(10, 2) NOT NULLPaymentTimeTIMESTAMP DEFAULT CURRENT_TIMESTAMP
c) Diagnosis of Double-Booking and Atomic Concurrency Solution
-
Diagnosis:
- A classic Race Condition (Lost Update / Phantom Update): Two drivers query the database simultaneously when
TripStatus = 'Requested'. Both read the row before either updates it, and both issueUPDATE Trip SET DriverID = ?, TripStatus = 'Accepted' WHERE TripID = ?, resulting in a double-booking collision.
- A classic Race Condition (Lost Update / Phantom Update): Two drivers query the database simultaneously when
-
Atomic Transaction Solution using Pessimistic Locking (
FOR UPDATE):
START TRANSACTION; -- Lock the specific trip row against concurrent reader-writers: SELECT TripID, TripStatus FROM Trip WHERE TripID = 10052 FOR UPDATE; -- Verify within the locked context that the trip is still unassigned: -- (Application logic checks: IF TripStatus == 'Requested') UPDATE Trip SET DriverID = 402, TripStatus = 'Accepted' WHERE TripID = 10052 AND TripStatus = 'Requested'; -- Update the accepting driver's operational status: UPDATE Driver SET Status = 'OnTrip' WHERE DriverID = 402; COMMIT;Mechanism: The
SELECT ... FOR UPDATEstatement locks the specific trip row at the database storage engine level (row-level exclusive lock). If Driver B attempts to accept the same trip while Driver A’s transaction is in flight, Driver B’s query blocks until Driver A commits. Upon release, Driver B readsTripStatus = 'Accepted', preventing duplicate assignment. - Core Entities & Business Rules: