NivaarExam PrepOfficial exam papers ↗

25-Comp-B3 Data Bases and File Systems · December 2014

Question 5 of 8: SQL — Doctor/Patient/Visit

Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)

Notes on this paper

98-Comp-B3, Data Bases & File Systems — National Exams, December 2014. 3 hours, closed book (calculators permitted). Candidates were instructed to answer five questions: one of Questions 1/2, one of Questions 3/4, and three of Questions 5–8 — only those five are marked. All 8 questions are answered below for completeness (this is a study resource covering the full syllabus).

Check: the source page header prints “98-Comp-B3/ December 2014” while the title block prints “National Exams May 2014” — a date inconsistency on the printed cover page. This is treated as the December 2014 exam period, matching every subsequent page header. Also, the page-1 marking scheme lists Question 8 as having two part-(c) entries (“(c) 4 marks; (c) 6 marks”); read as a mislabelled (c)/(d), matching the body text's actual four sub-parts (a)(b)(c)(d).

Reference texts: Silberschatz, Korth & Sudarshan, Database System Concepts (7th ed.) — RAID, indexing, ER modelling, normal forms, transactions and serializability; Ramakrishnan & Gehrke, Database Management Systems (3rd ed.) — B+-tree indexing, SQL, relational algebra, and concurrency control.

Question 5: SQL — Doctor/Patient/Visit (20 marks)

Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.

Given. Doctor(licno, drname, specialty), Patient(patid, patname, address, phone, DOB), Visit(licno, patid, date, type, diagnosis, charge), with Visit.licno/patid foreign keys into Doctor/Patient.

(a) All doctors and their specialties — a direct projection, no join needed.

SELECT drname, specialty
FROM   Doctor;

(b) licno of doctors who saw patient Mary Adams — join Visit to Patient on patid, filter by name.

SELECT DISTINCT V.licno
FROM   Visit V, Patient P
WHERE  V.patid = P.patid AND P.patname = 'Mary Adams';

(c) names of doctors who have made house calls — join Doctor to Visit on licno, filter by visit type.

SELECT DISTINCT D.drname
FROM   Doctor D, Visit V
WHERE  D.licno = V.licno AND V.type = 'house call';

(d) names and addresses of patients diagnosed with peptic ulcers — join Patient to Visit on patid, filter by diagnosis.

SELECT DISTINCT P.patname, P.address
FROM   Patient P, Visit V
WHERE  P.patid = V.patid AND V.diagnosis = 'peptic ulcer';
Sample-data check — Question 5
QueryResult on the sample dataset
(a)(Chen, Cardiology), (Osei, Pediatrics), (Blake, GeneralPractice)
(b)licno 1, 3
(c)Blake
(d)Mary Adams, John Kim