Grade 12 · Databases & SQL · Lesson and quiz · about 10 minutes
Grade 12 IT connects Delphi to a database (usually a Microsoft Access .mdb/.accdb file at school). The vocabulary:
- Table — data arranged in rows and columns (like tblLearners).
- Record — one row: everything about one learner.
- Field — one column: Surname, ITMark…
- Primary key — the field that uniquely identifies each record (LearnerID). No duplicates, never empty.
The Delphi components that do the talking, as wired in the exam skeletons:
- TADOConnection — connects the program to the database file.
- TADOQuery — holds and runs your SQL.
- TDataSource + TDBGrid — pipe the results onto the form as a grid.
And the two ways to fire SQL — this distinction is asked constantly:
// SELECT returns rows -> Open
qryLearners.SQL.Text := 'SELECT * FROM tblLearners';
qryLearners.Open;
// INSERT / UPDATE / DELETE change data -> ExecSQL
qryLearners.SQL.Text := 'DELETE FROM tblLearners WHERE ITMark < 50';
qryLearners.ExecSQL;
One Access habit worth knowing: Boolean (Yes/No) fields can be tested as WHERE Paid = True — and because True is stored as a number, WHERE Paid = 1 works too. Both forms work here as well.
Quick check
Question 1
One row of tblLearners — everything about one learner — is called a…
Answer
record — Row = record, column = field. One record holds all the fields for one entity.
Question 2
Why is LearnerID a good primary key?
Answer
It is unique for every learner and is never empty — A primary key must uniquely identify each record. Names cannot (two Thabo Mokoenas!), so we give each learner a unique ID.
Question 3
Your SQL is UPDATE tblLearners SET ClassCode = 'B' WHERE LearnerID = 3. How do you run it?
Answer
qryLearners.ExecSQL — UPDATE changes data and returns no rows, so it needs ExecSQL. Open is only for SELECT — using it on an action query is a favourite trick question.
Question 4
Which component actually holds and executes the SQL statement?
Answer
TADOQuery — The TADOQuery holds the SQL (qry.SQL.Text). The DataSource and DBGrid only display what the query returns.