Parameterised UPDATE and DELETE from code
A parameterised DELETE or UPDATE run from code: the ? in WHERE is filled by a value so only that record changes. cursor.rowcount of 0 means record not found.
Understanding Parameterised UPDATE and DELETE from code in QCE Digital Solutions Unit 2
What it does: Both the new value and the studentId are passed as placeholders, so only the row with studentId 3 is updated. A rowcount of 0 shows that no record matched the placeholder value, so the program tells the user the record was not found. The WHERE studentId = ? placeholder limits the delete to one record. Without WHERE, every row in the table is deleted. In parameterised SQL, each ? is replaced by a value from the tuple you pass to execute(). It is not a wildcard. Pass values as a tuple in the same order as the ? marks. Joining text into the SQL string risks SQL injection and bugs.
Common mistakes: The id is hard-coded as 5, so there is no ? placeholder. The code would always target student 5, and the (sid,) value would not match any placeholder. It should be sql += ' WHERE studentId = ?'. SQL assigns a new value in SET with =, not the word TO. The line should be sql += ' SET stock = ?'.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 337–409) and word search (Modules 234–409).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
DELETE FROM students WHERE studentId = ?Fill in the Blanks
Spot the Error
Student with a class code? Join your class →