SQL languages, queries and updates
Construct two-table SQL using the complete required command set, then explain data updates and indexed-column maintenance.
Declarative database programming
- outline DDL versus DML;
- construct JOIN queries with relational operators, filtering, pattern matching and ordering;
- use SELECT, DISTINCT, FROM, WHERE, BETWEEN, ORDER BY, GROUP BY, HAVING, ASC, DESC, JOIN, LIKE %, AND, OR and NOT;
- explain INSERT INTO, UPDATE SET and DELETE plus indexed-column update cost.
Rapid Recall Deck
Attempt each card first. If a term is new, flip and study it, then answer it again without looking. Mark only secure recall as “Know it”.
DDL/DML + simple query
DDL or DML?
PATIENT(PatID, PatientName, PatientDOB) DOCTOR(DocID, DoctorName) VISIT(VisitID, PatID, DocID, VisitDate, Treatment, Cost)
Outline the difference between Data Definition Language (DDL) and Data Manipulation Language (DML). Then classify these actions: create the VISIT table; add a column; retrieve visits; insert a visit; update a visit; delete a visit.
DDL defines or changes database structures such as tables and columns. DML retrieves or changes the data stored in those structures. Create VISIT and add a column are DDL; retrieve, insert, update and delete rows are DML.
BETWEEN + ORDER BY
Using PATIENT(PatID, PatientName, PatientDOB), construct a query that returns PatientName for dates of birth between '2005-01-01' and '2007-12-31', ordered by patient name ascending.
SELECT PatientName FROM PATIENT WHERE PatientDOB BETWEEN '2005-01-01' AND '2007-12-31' ORDER BY PatientName ASC;
Pattern matching
DISTINCT + LIKE syntax drill
For this isolated syntax drill, assume a simplified table VISIT_LOG(VisitID, PatientName, Treatment). Construct a query that returns each PatientName only once when Treatment contains the word therapy anywhere in the text.
LIKE with wildcard characters around therapy.SELECT DISTINCT PatientName FROM VISIT_LOG WHERE Treatment LIKE '%therapy%';
The next page repeats the same requirement using the normalized PATIENT + VISIT schema and therefore requires a JOIN.
Use relationship keys
Two-table therapy query
Using PATIENT(PatID, PatientName, PatientDOB) and VISIT(VisitID, PatID, DocID, VisitDate, Treatment, Cost), construct a JOIN query that returns each patient name once when the treatment contains therapy.
SELECT DISTINCT P.PatientName FROM PATIENT AS P JOIN VISIT AS V ON P.PatID = V.PatID WHERE V.Treatment LIKE '%therapy%';
Relational + Boolean filters
BETWEEN + AND/OR/NOT
Using PATIENT and VISIT joined by PatID, return patient name, visit date and cost for visits costing 100–500; exclude treatments containing trial; accept treatments containing scan OR therapy; order newest visit first.
SELECT P.PatientName, V.VisitDate, V.Cost FROM PATIENT AS P JOIN VISIT AS V ON P.PatID = V.PatID WHERE V.Cost BETWEEN 100 AND 500 AND NOT V.Treatment LIKE '%trial%' AND (V.Treatment LIKE '%scan%' OR V.Treatment LIKE '%therapy%') ORDER BY V.VisitDate DESC;
GROUP BY + HAVING
Filter groups
Using VISIT(VisitID, PatID, DocID, VisitDate, Treatment, Cost), construct a query that lists each DocID and its visit count only for doctors with at least 5 visits, busiest first.
SELECT DocID, COUNT(*) AS VisitCount FROM VISIT GROUP BY DocID HAVING COUNT(*) >= 5 ORDER BY VisitCount DESC;
WHERE filters rows before grouping; HAVING filters groups after aggregation.
Update stored data
INSERT
INSERT INTO PATIENT (PatID, PatientName, PatientDOB) VALUES (105, 'Amina Noor', '2006-04-12');
UPDATE
UPDATE VISIT SET Cost = 140 WHERE VisitID = 9001;
DELETE
DELETE FROM VISIT WHERE VisitID = 9001;
Writes have maintenance costs
Indexed-column update
PatientDOB is indexed and a migration changes millions of DOB values. Explain the cost.
The DB must update the rows and index entries/order. Large changes add write/maintenance cost, can fragment index structures and may require indexes to be rebuilt or reorganized after significant modifications.
Finish the learning cycle
Case study / exam preparation
Post-IA focus: add one useful 2027 case-study research note and prioritize cumulative exam retrieval.
Paper 1 — short practice
Write one JOIN+LIKE+DISTINCT query, one BETWEEN+ORDER BY query, one GROUP BY+HAVING query, then INSERT/UPDATE/DELETE examples.