Database, Past Papers, UOS Main Campus

Database BSCS 4th Final Past Paper – UOS Main Campus

ProgramBSCS
Semester4th
ExamFinal Term
CampusUOS Main
AnswersSolved ✓

University of Sargodha main campus (Department of CS & IT) Database final term paper for BSCS 4th semester (Self), 50 marks, 120 minutes. Retyped from the original paper, with solved answers below.

Solved answers

Q1 – Olympic facilities EER (10)

Assumptions: every complex is either one-sport or multisport (total, disjoint specialization); an event takes place in exactly one complex; equipment can be shared by many events.

  • COMPLEX (ComplexID, Location, ChiefOrganizer, TotalArea, ComplexType) — supertype; ComplexType is the subtype discriminator.
  • ONE_SPORT_COMPLEX (Sport) and MULTISPORT_COMPLEX with the multivalued composite attribute {SportArea (Sport, LocationIndicator)}, e.g. (Hockey, NE corner).
  • FACILITY_TYPE (TypeCode, NumberOfFacilitiesNeeded, ApproxBudget) — one row for one-sport and one for multisport, because these values are kept per type, not per complex.
  • EVENT (EventID, EventName, PlannedDate, Duration, NoOfParticipants, NoOfOfficials). COMPLEX 1 —— Holds —— M EVENT.
  • OFFICIAL (OfficialID, Name). OFFICIAL M —— Officiates —— N EVENT (this gives the roster and each official’s list of events).
  • EQUIPMENT (EquipmentID, Description). EQUIPMENT M —— Used for —— N EVENT, and EQUIPMENT M —— Maintains —— N COMPLEX for maintenance equipment.

Q2 – Shipping manifest to 3NF (10)

Check of the manifest: 500 × 100 = 50,000; 87 × 2,000 = 174,000; shipment total = 224,000. Total weight and shipment total are derived, so they are not stored.

  • SHIPMENT (ShipmentID, ShipmentDate, Origin, Destination, ExpectedArrival, ShipNumber, CaptainID)
  • CAPTAIN (CaptainID, CaptainName)
  • ITEM (ItemNumber, Type, Description, Weight)
  • SHIPPED_ITEM (ShipmentID, ItemNumber, Quantity)

Referential integrity constraints: SHIPMENT.CaptainID → CAPTAIN.CaptainID; SHIPPED_ITEM.ShipmentID → SHIPMENT.ShipmentID; SHIPPED_ITEM.ItemNumber → ITEM.ItemNumber. (If ships have more attributes, add SHIP (ShipNumber, …) with SHIPMENT.ShipNumber → SHIP.ShipNumber.)

Q3 – SQL on the tutoring database (20)

-- I
ALTER TABLE STUDENT ADD MathScore NUMERIC(3,1);

-- II
ALTER TABLE TUTOR ADD Subject VARCHAR(7)
  CHECK (Subject IN ('Reading', 'Math', 'ESL'));

III. A single Subject column holds only one value, so a tutor teaching two subjects would need a duplicate row (not allowed: TutorID is the primary key). Remove Subject from TUTOR and create a separate table TUTOR_SUBJECT (TutorID, Subject), with one row per subject.

-- IV  tutors with no July report (result: 101, 102, 103, 104, 105)
SELECT TutorID FROM TUTOR
WHERE TutorID NOT IN (SELECT M.TutorID
                      FROM MATCH_HISTORY M JOIN TUTOR_REPORT R ON M.MatchID = R.MatchID
                      WHERE R.Month = '7/08');

V. Name, address, phone and e-mail describe the person, so they belong in the TUTOR and STUDENT tables themselves:

ALTER TABLE TUTOR   ADD (TutorName VARCHAR(40), Address VARCHAR(80), Phone VARCHAR(15), Email VARCHAR(50));
ALTER TABLE STUDENT ADD (StudentName VARCHAR(40), Address VARCHAR(80), Phone VARCHAR(15), Email VARCHAR(50));

-- VI  June activity (result: 3000 → 8 h, 4 lessons; 3003 → 8 h, 6; 3004 → 4 h, 4)
SELECT S.StudentID, S.StudentName, SUM(R.Hours) AS Hours, SUM(R.Lessons) AS Lessons
FROM STUDENT S JOIN MATCH_HISTORY M ON S.StudentID = M.StudentID
               JOIN TUTOR_REPORT R  ON M.MatchID = R.MatchID
WHERE R.Month = '6/08'
GROUP BY S.StudentID, S.StudentName;

-- VII  available tutors: active and not in an open match (result: 103)
SELECT TutorID, TutorName FROM TUTOR
WHERE Status = 'Active'
  AND TutorID NOT IN (SELECT TutorID FROM MATCH_HISTORY WHERE EndDate IS NULL);

-- VIII  tutors with an open match but no July report (result: 104)
SELECT DISTINCT T.TutorID, T.TutorName
FROM TUTOR T JOIN MATCH_HISTORY M ON T.TutorID = M.TutorID
WHERE M.EndDate IS NULL
  AND M.MatchID NOT IN (SELECT MatchID FROM TUTOR_REPORT WHERE Month = '7/08');

-- IX
ALTER TABLE TUTOR DROP PRIMARY KEY;
ALTER TABLE TUTOR ADD PRIMARY KEY (CertDate);

Note on IX: this fails on the given data, because CertDate is not unique (several tutors share 1/05/2008 and 5/22/2008) and MATCH_HISTORY references TutorID. CertDate is not a suitable primary key; this is the point of the question.

-- X
ALTER TABLE MATCH_HISTORY ADD Winner VARCHAR(30);

-- XI
ALTER TABLE MATCH_HISTORY
  ADD CONSTRAINT fk_mh_tutor   FOREIGN KEY (TutorID)   REFERENCES TUTOR(TutorID);
ALTER TABLE MATCH_HISTORY
  ADD CONSTRAINT fk_mh_student FOREIGN KEY (StudentID) REFERENCES STUDENT(StudentID);

-- XII  audit trigger (Oracle)
CREATE TABLE MATCH_HISTORY_LOG (
  MatchID NUMBER, TutorID NUMBER, StudentID NUMBER,
  StartDate DATE, EndDate DATE, ChangedOn DATE
);

CREATE OR REPLACE TRIGGER trg_match_history_audit
BEFORE UPDATE ON MATCH_HISTORY
FOR EACH ROW
BEGIN
  INSERT INTO MATCH_HISTORY_LOG
  VALUES (:OLD.MatchID, :OLD.TutorID, :OLD.StudentID, :OLD.StartDate, :OLD.EndDate, SYSDATE);
END;
/

The results in comments were checked by running the queries on the sample data in the paper.

Q4 – Project viva voce (10)

Be ready to explain your project’s ERD, how you converted it into tables, the normal form of each table, your primary and foreign keys, and to run or explain a few SQL queries, a view and a trigger from your project.

Save this paper for offline studyDownload the question paper, or save the paper together with all solved answers as a PDF.
↓ Download Paper (JPG)

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.