Database, Past Papers, University of the Punjab

Database Systems Past Paper Spring 2025 – BS 4th Semester Punjab University (CC-215)

Semester4th
Year2025
Course codeCC-215
AnswersSolved ✓

University of the Punjab BS 4-year programme, fourth semester Spring 2025, Database Systems (CC-215) paper (60 marks, 3 hours). The question paper is the official University of the Punjab paper published on pu.edu.pk (BS 4-year programme past papers, Spring 2025); it is retyped here and the answers are written by Shining Study. Solved answers: database components, data models, keys, integrity, concurrency and recovery, an ER design for a car repair shop, normalisation of PROJECT to 3NF and SQL queries tested in SQLite.

Solved answers

Q1 – Short answers (6 × 5)

a. Components of a database system. Hardware (servers, storage, network); software (DBMS such as MySQL/Oracle, OS, application programs); data (the actual data plus metadata stored in the data dictionary); procedures (rules and instructions for using, backing up and recovering the database); and people – database administrators, database designers, application programmers and end users.

b. Data model and its types. A data model is a simple (usually graphical) representation of data structures, relationships and constraints used to design a database. Types: hierarchical (tree, parent–child), network (records linked by sets, many-to-many), relational (tables/relations – most common), entity–relationship (conceptual ER diagrams), object-oriented (objects with attributes and methods), plus object-relational, NoSQL/document and semi-structured (XML/JSON) models. By level: conceptual, logical (implementation) and physical models.

c. Super, candidate and primary keys. Example STUDENT(StdID, CNIC, Email, Name, Dept).
Super key: any attribute set that uniquely identifies a row – {StdID}, {StdID, Name}, {CNIC, Dept}…
Candidate key: a minimal super key (no attribute can be removed) – StdID, CNIC, Email.
Primary key: the candidate key chosen by the designer to identify rows; unique and not null – StdID. The others become alternate keys.

d. Entity and referential integrity. Entity integrity: every table has a primary key and no part of it may be NULL, so every row is uniquely identifiable (a STUDENT row cannot have StdID = NULL).
Referential integrity: a foreign key value must either match an existing primary key value in the referenced table or be NULL. Example: ENROLL(StdID, CourseID) – StdID must exist in STUDENT; you cannot insert an enrollment for StdID 999 if no such student exists, and deleting a referenced student is restricted or cascaded.

e. Concurrent transactions and their problems. Concurrent transactions are two or more transactions executing at the same time on shared data (interleaved operations), which improves throughput. Without concurrency control problems occur: lost update (two transactions read the same value and one overwrites the other’s update); uncommitted data / dirty read (T2 reads a value written by T1 that is later rolled back); inconsistent retrieval (a summary reads some values before and some after another transaction’s update); also unrepeatable reads and phantom rows. Locking (2PL), timestamps and isolation levels solve them.

f. Transaction log and change log in recovery. The transaction log records every transaction’s start, each update (before-image and after-image), and commit/abort. After a failure the DBMS uses it to UNDO changes of uncommitted transactions (using before-images) and REDO changes of committed transactions not yet written to disk (using after-images), restoring a consistent state. Checkpoints limit how much of the log must be scanned. The database change log (before/after images of changed records) together with backups allows roll-forward of a restored backup to the point of failure.

Q2 – ER diagram: automobile body repair shop

Entities and attributes (PK underlined):

EntityAttributes
CUSTOMERCustomerID, Name, Phone, Address
CARRegNo, Make, Model, Year, Color, CustomerID (FK)
MECHANICMechanicID, Name, Phone
ESTIMATEEstimateNo, EstDate, EstCost, EstTime, Accepted (Y/N)
JOBJobNo, AppointmentDate, StartDate, EndDate, Status
REPAIR (weak, part of JOB)JobNo + RepairNo, Description, ActualHours, LaborCost (= ActualHours × HourlyRate)
PARTPartNo, Description, UnitPrice

Relationships and cardinalities

  • CUSTOMER owns CAR – 1 : M (a customer may own many cars; each car has one owner).
  • CAR receives ESTIMATE – 1 : M; MECHANIC prepares ESTIMATE – 1 : M.
  • ESTIMATE becomes JOB – 1 : 0..1 (a job is created only if the estimate is accepted; the job number is assigned then).
  • MECHANIC works on JOB – 1 : M (only one mechanic works on a car for the entire job).
  • JOB includes REPAIR – 1 : M (identifying relationship; REPAIR is a weak entity).
  • REPAIR uses PART – M : N with associative entity REPAIR_PART(Qty, Charge) to track charges for parts as they accumulate.
CUSTOMER ──1──<owns>──M── CAR ──1──<receives>──M── ESTIMATE ──1──<becomes>──0..1── JOB
                                                         │M                              │M   │1
                                             MECHANIC ──1┘ (prepares)        MECHANIC ──1┘    │
                                                                             (works on)       │M
                                                         PART ──M──<uses: Qty, Charge>──N── REPAIR (weak)

The fixed hourly labour rate can be stored once in a SHOP_SETTINGS table (or as a constant) and labour cost = ActualHours × rate; total job cost = Σ labour + Σ parts charges.

Q3 – Normalising PROJECT up to 3NF

Unnormalised (UNF): PROJECT(PROJNO, PROJNAME, BUDGET, STARTDATE, PROJMGR, {EMPID, HOURS, EMPNAME, SALARY, EMPMGR, DEPTNO, DNAME, RATING}) – one project row holds a repeating group of employees.

1NF (definition: all attributes atomic, no repeating groups, a primary key identifies each row). Flatten the repeating group: primary key becomes (PROJNO, EMPID).

Functional dependencies:

  • PROJNO, EMPID → HOURS, RATING (full dependency)
  • PROJNO → PROJNAME, BUDGET, STARTDATE, PROJMGR (partial)
  • EMPID → EMPNAME, SALARY, EMPMGR, DEPTNO, DNAME (partial)
  • DEPTNO → DNAME (transitive: EMPID → DEPTNO → DNAME)

Anomalies in 1NF: insertion – a new project with no employees cannot be stored (EMPID is part of the key); update – changing a project’s budget or an employee’s salary must be repeated in many rows; deletion – deleting the last employee of a project deletes the project data too.

2NF (1NF + no partial dependency of a non-key attribute on part of a composite key):

  • PROJECT(PROJNO, PROJNAME, BUDGET, STARTDATE, PROJMGR)
  • EMPLOYEE(EMPID, EMPNAME, SALARY, EMPMGR, DEPTNO, DNAME)
  • ASSIGNMENT(PROJNO, EMPID, HOURS, RATING)

Remaining anomaly: in EMPLOYEE, DNAME depends on DEPTNO, so a department name is repeated for every employee and a department without employees cannot be stored.

3NF (2NF + no transitive dependency of a non-key attribute on the key): split DEPTNO → DNAME.

Table (3NF)KeyNotes
PROJECT(PROJNO, PROJNAME, BUDGET, STARTDATE, PROJMGR)PROJNOPROJMGR → EMPLOYEE(EMPID)
EMPLOYEE(EMPID, EMPNAME, SALARY, EMPMGR, DEPTNO)EMPIDEMPMGR → EMPLOYEE(EMPID); DEPTNO → DEPARTMENT
DEPARTMENT(DEPTNO, DNAME)DEPTNO
ASSIGNMENT(PROJNO, EMPID, HOURS, RATING)PROJNO + EMPIDFKs to PROJECT and EMPLOYEE

Q4 – SQL queries

Note: as printed, PURCHASES has no customer column and there is no PRODUCT table, so parts (b)–(e) cannot be answered exactly. The usual intended design adds CUSTNO as a foreign key in PURCHASES and a PRODUCT(PROD_NAME, …) table; the queries below use that assumption (column C_PH# may need quotes/brackets in some DBMSs). All queries were tested in SQLite on sample data.

-- a) names starting with 'S' and income 30000–50000
SELECT * FROM CUSTOMER
WHERE C_NAME LIKE 'S%' AND INCOME BETWEEN 30000 AND 50000;

-- b) purchases of a given customer (e.g. CUSTNO = 101)
SELECT * FROM PURCHASES WHERE CUSTNO = 101;

-- c) customer with purchase details
SELECT C.CUSTNO, C.C_NAME, P.PROD_NAME, P.PRICE, P.QTY
FROM CUSTOMER C JOIN PURCHASES P ON C.CUSTNO = P.CUSTNO;

-- d) customer with the lowest total purchases
SELECT C.C_NAME
FROM CUSTOMER C JOIN PURCHASES P ON C.CUSTNO = P.CUSTNO
GROUP BY C.CUSTNO, C.C_NAME
HAVING SUM(P.PRICE * P.QTY) = (SELECT MIN(T)
                               FROM (SELECT SUM(PRICE * QTY) AS T
                                     FROM PURCHASES GROUP BY CUSTNO) X);

-- e) unsold products
SELECT PROD_NAME FROM PRODUCT
WHERE PROD_NAME NOT IN (SELECT PROD_NAME FROM PURCHASES);
Save this paper for offline studyDownload the question paper, or save the paper together with all solved answers as a PDF.
↓ Download Paper (JPG)
Have another year of Database?

Upload a photo in 10 seconds — no form to fill. We clean it, solve it and credit you.

Missing years for this subject
202320222021

About Saif R

An educator and technology enthusiast passionate about empowering students through quality education and digital learning. Dedicated to making academic resources and opportunities accessible to everyone.