This note is from 2 months ago. You're viewing content from a previous lesson.
You are moving beyond “writing SQL queries” into understanding SQL as a full system for defining, manipulating, securing, and maintaining data integrity.
This activity requires you to:
Outline (command term: brief but precise distinctions)
Construct (command term: produce correct SQL code)
Explain (command term: give reasons/mechanisms)
Describe (command term: detailed features and characteristics)
These command terms are explicitly defined in the IB guide and will be enforced strictly.
You are working on a hospital management system with the following schema:
PATIENT(patient_id, name, date_of_birth, insurance_type)
DOCTOR(doctor_id, name, specialty)
APPOINTMENT(appointment_id, patient_id, doctor_id, date, cost)
TREATMENT(treatment_id, appointment_id, description, success)
Constraints:
A patient may have many appointments
A doctor may handle many appointments
Each appointment may include multiple treatments
The system is used in real-time, requiring high integrity and performance
QUESTION 1: Outline the differences between:
DDL
DML
TCL
Include purpose
Include example commands
Include effect on database state
Weak (1–2 marks):
DDL creates tables, DML changes data.
Strong (3 marks):
DDL defines database structure (e.g., CREATE, ALTER) and modifies schema, while DML manipulates data within tables (e.g., SELECT, INSERT). TCL manages transactions (e.g., COMMIT, ROLLBACK), controlling persistence and consistency.
Command Term: Construct (8 marks)
Write a query that returns:
Patient name
Doctor name
Total cost of all appointments per patient
Only include patients with total cost > 500
Only include doctors with specialty = 'Cardiology'
Sort by total cost descending
Must include:
JOIN
GROUP BY
HAVING
ORDER BY
Aggregate function
Command Term: Explain (6 marks)
Explain how SQL updates data in this system.
Include:
INSERT
UPDATE
DELETE
Then answer:
What are the performance and integrity risks of updating indexed columns in a high-volume hospital system?
Weak:
UPDATE changes values in a table.
Strong:
UPDATE modifies existing tuples and may trigger index restructuring; frequent updates to indexed columns degrade performance due to rebalancing and can introduce temporary inconsistencies if not transaction-controlled.
Command Term: Construct (6 marks)
Write a query that calculates:
Average treatment cost per doctor
Number of treatments per doctor
Only include doctors with more than 10 treatments
Command Term: Describe (6 marks)
Describe:
Virtual views
Materialized views
Then evaluate:
Which is more appropriate for a hospital dashboard showing real-time patient loads?
Performance implications
Data freshness
Storage trade-offs
Command Term: Describe (8 marks)
A patient undergoes a treatment:
Appointment is created
Treatment is recorded
Billing is updated
Write a transaction sequence using SQL.
Then:
Explain how ACID properties ensure correctness.
BEGIN TRANSACTION;
-- your operations
COMMIT;
-- OR ROLLBACK;
Atomicity
Consistency
Isolation
Durability
Design a failure scenario where:
A transaction partially completes
Data becomes inconsistent
Then:
Explain precisely how ACID prevents this
| Criterion | Requirement | Check |
|---|---|---|
| A | Correct distinction of SQL language types | ☐ |
| B | Fully correct multi-table query | ☐ |
| C | Deep explanation of update mechanisms + risks | ☐ |
| D (HL) | Correct aggregate query with filtering | ☐ |
| E (HL) | Accurate comparison of views | ☐ |
| F (HL) | Correct transaction + ACID explanation | ☐ |