GCSE · Computer Science · AQA · Spec 8525

SQL UPDATE

One short statement can change a whole table of records at once. Brilliant when you aim it. A disaster when you forget one tiny line. Which line?

Computer Science · Databases

One UPDATE, every matching record

Predict which records change, then step through the table and watch each record face the WHERE test. The page shows the steps the lesson wrote out; it does not run the SQL.

Before you step: which of the six records do you think will change, and what will they change to?

UPDATE tblLessons
SET CourseID = 2
WHERE CourseID = 1;

Result

MemberIDNameCourseID
1Asha1
2Ben2
3Chloe1
4Dev3
5Ella1
6Femi2

Output

 

Step 1: Here is tblLessons before anything runs: six records. CourseID 1 is the Ducklings course and CourseID 2 is Dippers (CourseID 3 is another course). Make your prediction, then step through.

1 / 8

Press Next and, for each record, decide for yourself whether it passes the WHERE test before you read the note.

Step 1 of 8: Here is tblLessons before anything runs: six records. CourseID 1 is the Ducklings course and CourseID 2 is Dippers (CourseID 3 is another course). Make your prediction, then step through..

Exam line: UPDATE rewrites values inside records that already exist. Every record that passes the WHERE test changes, and the rest stay exactly as they were.
Watch out: The table at each step is written out by hand for teaching; the page is not a database and does not run the statement.

Your turn

Finish the statement

Chloe (MemberID 3) is on CourseID 1 and is moving to CourseID 3. The first two lines are written for you. Finish the UPDATE so that it changes her record only, by testing her MemberID and also that she is on CourseID 1.

  1. UPDATE tblLessonsUPDATE and the table name come first.
  2. SET CourseID = 3SET goes on the next line and names the field to overwrite, with its new value.
  3. missing step
Which line is step 3?

Check the work

Which line goes wrong?

The student wants member 4 moved to CourseID 2, but only if that member's record is on CourseID 1 or CourseID 3. Read the statement and pick the line that goes wrong.

A student's statement — which line goes wrong?

Exam line: When a WHERE clause mixes OR and AND, check which part is worked out first. Brackets make the OR happen first.

What would happen?

The missing line

tblLessons has six records, and someone runs the statement below without a WHERE line. UPDATE tblLessons SET CourseID = 2;

What happens when UPDATE tblLessons SET CourseID = 2; is run with no WHERE clause?
How sure are you?

Compare the four

What does each command do?

For each command, tick every job it does to the records in a table. Then check your grid.

SELECT
INSERT
UPDATE
DELETE

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

One statement, a whole table of records. Find out which ones change, which ones don't, and what happens when you forget a line.

What you need to know

  • SQL (structured query language) manages data in relational databases using standardised commands, and each statement must follow syntax rules to run correctly.
  • Four common jobs: SELECT searches and retrieves records, INSERT adds new ones, DELETE removes records, and UPDATE changes records that already exist.
  • UPDATE edits the values inside records that are already there. The rows stay; their contents change.
  • Have a goYour classmate says, very confidently, that UPDATE adds a new record holding the new values. Fair, or have they mixed it up with something?

    Mixed up. UPDATE changes values inside records that already exist.

    Adding new records is INSERT's job; UPDATE leaves the existing rows in place and changes what is inside them.

  • Three parts: UPDATE and the table, then SET on the next line (field1 = value1, field2 = value2), then WHERE.
  • WHERE is the test. Every record that passes it is changed, not just the first one.
  • Have a goA table has 10 records and 4 of them pass the WHERE test. How many records get changed?

    All 4 of them, and the table still has 10 records.

    Every record that passes WHERE is changed, not just the first one, and no records are added or removed.

  • Leave WHERE out and there is no test, so every record in the table changes.
  • Need more than one test? Join them with AND or OR. Don't write WHERE again, and end the statement with a semicolon.
  • AND needs both tests to be true. OR needs at least one of them to be true.
  • AND takes precedence over OR, like multiplication over addition in arithmetic, so AND is worked out first.
  • Have a goLook at WHERE x = 1 OR y = 2 AND z = 3. Which part does SQL work out first?

    y = 2 AND z = 3

    AND takes precedence over OR, just as multiplication goes before addition, so reading left to right is the tempting wrong order.

The big picture

An SQL UPDATE statement changes values in records that already exist. It is written as UPDATE and the table name, then SET with field = value pairs, then a WHERE clause that says which records change. Every record that passes the WHERE test is changed, and with no WHERE every record changes. AND and OR add more tests, and AND is worked out before OR.

Key points

1UPDATE changes values inside records that already exist; no rows are added or removed.
2Write it as UPDATE and the table, SET field = value, then WHERE criteria, and finish with a semicolon.
3Every record that passes WHERE is changed. With no WHERE, every record changes.
4Extra tests join on with AND or OR, without writing WHERE again, and AND is worked out before OR.

Worked example

Problem

tblLessons holds six records (MemberID, Name, CourseID): 1 Asha 1, 2 Ben 2, 3 Chloe 1, 4 Dev 3, 5 Ella 1, 6 Femi 2. Predict the table after this statement runs: UPDATE tblLessons SET CourseID = 3 WHERE CourseID = 2 AND MemberID = 6;

⚠ Watch out

Thinking UPDATE changes only the first match, adds a new record, or is harmless without a WHERE line. In fact every matching record changes, no rows are added or removed, and with no WHERE every record changes.

🧠

Memory hook

Think of WHERE as the guest list for an edit. Every record on the list gets changed; leave the list out and everyone is invited. (The analogy ends there: UPDATE edits records that are already in the table, it never adds guests.)

✓

Check yourself

Without looking back, write the UPDATE that changes Dev's CourseID to 1 (his MemberID is 4). Then say what would happen to the other five records if you forgot the WHERE line.

Flashcards

(11)
What does SQL stand for, and what is it used for?
Structured query language. It manages data in relational databases through standardised commands.
What does an UPDATE statement do?
It changes existing records in a table: values inside records that are already there.
What are the three parts of an UPDATE statement, in order?
UPDATE and the table name, then SET on the next line with field = value pairs, then WHERE with the criteria.
How do you change two fields in one UPDATE?
Put both in SET, separated by commas: SET field1 = value1, field2 = value2.
What does the WHERE clause do in an UPDATE?
It says which records are changed. Every record that passes its test is changed.
What happens if an UPDATE has no WHERE clause?
There is no test, so every record in the table is changed.
How do you add a second condition to a WHERE clause?
Use AND or OR. You do not write WHERE a second time.
Which comes first in a WHERE clause, AND or OR?
AND. It takes precedence over OR, like multiplication over addition in arithmetic.
Name the four common SQL operations.
SELECT searches and retrieves, INSERT adds new records, DELETE removes records, UPDATE changes existing records.
What goes at the end of an SQL statement?
A semicolon.
After an UPDATE runs, has the number of records changed?
No. No rows are added or removed. Only values inside the matching records change.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 4 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.