Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Name: Uzair Naseer

Roll No: 04162113047

Semester: BS-IT(4rth) Morning


Course: IT-232 (Database Systems)

Teacher: Ma’am Bushra

Date: May 31, 2023


LAB ASSIGNMENT
1. [CLO-1][CLO-2]Draw an ERD/EERD.
2. [CLO-3]Create a relational model based on the ERD you developed in part a.
3. [CLO-5]Write SQL queries and their corresponding relational algebra statements for following.
a. Display the list of workers working in first shift Monday.
b. Display the prescriptions for a particular patient admitted to the emergency.

Identification of Relationships and Constraints:

Person - Contact: "Person has Contact"


Cardinality: One-to-Many
Worker - Receptionist/Nurse/Doctor: "Worker assumes Role"
Cardinality: One-to-One
Shift - Receptionist/Nurse/Doctor: "Shift assigns Worker"
Cardinality: Many-to-Many
Shift - Patient: "Shift admits Patient"
Cardinality: Many-to-One
Shift - Triage: "Shift conducts Triage"
Cardinality: One-to-Many
Shift - Bed: "Shift has Bed"
Cardinality: One-to-Many
Patient - Admission: "Patient undergoes Admission"
Cardinality: One-to-One
Patient - Prescription: "Patient receives Prescription"
Cardinality: One-to-Many
Doctor - Prescription: "Doctor prescribes Medication"
Cardinality: One-to-Many
Medication - Prescription: "Prescription includes Medication"
Cardinality: One-to-Many
Patient - Bed:"Patient occupies Bed"
Cardinality: One-to-Many
AmbulanceService - Patient: "AmbulanceService transports Patient"
Cardinality: One-to-Many

Page-2
ER-DIAGRAM TO RELATIONAL MODELLING:

Page-3
ER-DIAGRAM TO RELATIONAL MODELLING:

Page-4
ER-DIAGRAM TO RELATIONAL MODELLING:

SQL and Relational Aljebra:


4. Write SQL queries and their corresponding relational algebra statements for the following.
c. Display the list of workers working in first shift Monday.
d. Display the prescriptions for a particular patient admitted to the emergency.

Page-5
1. Monday Morning Workers:
SELECT w.first_name, w.last_name, w.middle_name
FROM worker AS w
JOIN shift AS s ON w.shift_id = s.id
WHERE s.start_time >= 'YYYY-MM-DD 00:00:00' AND s.start_time < 'YYYY-MM-DD
23:59:59' AND DAYNAME(s.start_time) = 'Monday'

Corresponding Relational Algebra:


π w.first_name, w.last_name, w.middle_name (σ s.start_time >= 'YYYY-MM-DD 00:00:00'
AND s.start_time < 'YYYY-MM-DD 23:59:59' AND DAYNAME(s.start_time) = 'Monday'
(worker ⨝ worker.shift_id = shift.id shift))

2. Patient’s Prescription:
SELECT p.first_name, p.last_name, m.name, pr.dosage, pr.times_per_day
FROM patient AS pt
JOIN prescription AS pr ON pt.id = pr.patient_id
JOIN medication AS m ON pr.medication_id = m.id
JOIN person AS p ON pt.person_id = p.id
WHERE pt.id = <patient_id>

Corresponding Relational Algebra:


π p.first_name, p.last_name, m.name, pr.dosage, pr.times_per_day (σ pt.id = <patient_id>
(patient ⨝ patient.person_id = person.id ⨝ prescription.patient_id = patient.id ⨝
prescription.medication_id = medication.id))

-------------THE END -------------

Page-6

You might also like