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
| MemberID | Name | CourseID |
|---|---|---|
| 1 | Asha | 1 |
| 2 | Ben | 2 |
| 3 | Chloe | 1 |
| 4 | Dev | 3 |
| 5 | Ella | 1 |
| 6 | Femi | 2 |
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.
Press Next and, for each record, decide for yourself whether it passes the WHERE test before you read the note.
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
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?
What does an UPDATE statement do?
What are the three parts of an UPDATE statement, in order?
How do you change two fields in one UPDATE?
What does the WHERE clause do in an UPDATE?
What happens if an UPDATE has no WHERE clause?
How do you add a second condition to a WHERE clause?
Which comes first in a WHERE clause, AND or OR?
Name the four common SQL operations.
What goes at the end of an SQL statement?
After an UPDATE runs, has the number of records changed?
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 postedMore AQA GCSE Computer Science topics
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.