LearnStanmorephysics

Grade 12 · Matric Mastery

Database ideas & Delphi wiring

Grade 12 · Databases & SQL · Lesson and quiz · about 10 minutes

Take this lesson in the app →

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…

  1. field
  2. record
  3. primary key
  4. query
Answer

record — Row = record, column = field. One record holds all the fields for one entity.

Question 2

Why is LearnerID a good primary key?

  1. It is the shortest field
  2. It comes first alphabetically
  3. It is a number, and numbers search faster
  4. It is unique for every learner and is never empty
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?

  1. qryLearners.Open
  2. qryLearners.ExecSQL
  3. qryLearners.Show
  4. qryLearners.Run
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?

  1. TDBGrid
  2. TDataSource
  3. TADOQuery
  4. TLabel
Answer

TADOQuery — The TADOQuery holds the SQL (qry.SQL.Text). The DataSource and DBGrid only display what the query returns.

About this material

This platform provides original CAPS-aligned practice material and study tools. Content is machine-verified and has not been reviewed by subject specialists. It is not affiliated with or endorsed by the Department of Basic Education. Learners should also use official past papers and consult their teachers where uncertain.