GCSE · Computer Science · Eduqas · Spec C500QS
SQL injection
You press enter on a search box and a database gets asked a question. Who wrote that question: the programmer, or you?
Computer Science · Cybersecurity
Same typed text, very different endings
Start with text typed into the box. Choose a branch at each fork to see how the system's design decides the ending.
Is the input checked? → How is the query built? → Database account rights → What the commands are used for
6 possible endings.
Follow text typed into a box through the system. At each fork, pick the design condition and see where it ends up.
Computer Science · Databases
How a search box builds a query
A harmless search, step by step. Watch where the typed word ends up.
A shopper types Mug into a shop's search box. What does the database actually receive?
SELECT name, price FROM Product WHERE name = 'Mug'
Result
| name | price |
|---|---|
| (no rows yet) | |
Output
Step 1: The programmer wrote the start of the query text: SELECT name, price FROM Product WHERE name = and then the system waits for what the shopper types.
Step through with Next and watch the typed word join the fixed query text.
Why injection works
Reason it through
Why can text typed into a box make a database run commands?
First link · your turn
A poorly built system takes what you typed. Where does it put that text?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
How text typed into a box can end up as part of a database query, and the design choices that stop it
What you need to know
- SQL is a language for searching, adding, changing and deleting data held in a database.
- Lots of sites build an SQL query from what you type: a login's username and password boxes, or a search box.
Have a goSam says: "The word I type in a search box is just something to look for. It never goes anywhere near SQL." What is Sam missing?
Many sites build an SQL query out of what you type.
Sam treats the typed text as only a word to look for, but the site uses it to build the query it sends to the database.
- SQL injection is a cybersecurity threat. The attacker types SQL commands into an input box instead of the expected data.
- Those commands then become part of the query the system sends to its database.
- It works when a poorly built system puts typed input straight into the query without checking it.
- The database can't tell the attacker's commands from the intended query, so it runs them.
Have a goA system pastes typed input into its query and checks nothing. Why does the database run an attacker's commands instead of ignoring them?
It can't tell them apart from the intended query.
The commands sit inside the query it was sent, so nothing marks them as typed by someone else.
- A successful attack can expose data, change or delete data, or get past a login without a valid password.
- Input checking (validation and sanitisation) helps: it checks input first and rejects or removes what doesn't match what's expected.
- Parameterised queries (prepared statements) prevent it: the query's structure is fixed in advance and input goes in only as data.
Have a goInput checking, parameterised queries, least privilege: which one passes input in only as data, so it is never run as a command?
Parameterised queries.
Input checking helps by rejecting or removing input, and least privilege only limits the damage. Only parameterised queries fix the query's structure in advance.
- Least privilege means the database account has only the rights it needs, which limits how much a successful attack could expose or change.
The big picture
SQL injection happens when a poorly built system puts what a user types straight into its own SQL query without checking it, so typed commands become part of the query and the database runs them. A successful attack can expose data, change or delete data, or get past a login. Parameterised queries prevent it, input checking helps, and least privilege limits the damage.
Key points
Worked example
Problem
A school builds a login page. The developer (A) puts what the user types straight into the SQL query, (B) adds no input checking, and (C) lets the page use a database account with every right in the database. Which of A, B and C make an SQL injection possible, which make it worse, and what fixes each?
⚠ Watch out
Saying least privilege stops SQL injection. It doesn't stop the commands running; it only limits how much data a successful attack could expose or change. Parameterised queries are the defence that keeps input as data.
Memory hook
Fix the query, check the input, shrink the rights: parameterised queries prevent it, input checking helps, and least privilege limits the damage.
Check yourself
Why can text typed into a search box end up run as database commands? Name the design choice behind it and the defence that keeps input as data.
Flashcards
(12)What is SQL used for?
Name two places where a site might build an SQL query from typed input.
What is SQL injection?
When does SQL injection succeed?
Name three things a successful SQL injection can do.
What data might a successful injection expose?
What are the two parts of input checking?
What is a parameterised query (prepared statement)?
In SQL injection, who actually builds the query that gets abused?
What is least privilege?
Does least privilege stop an SQL injection happening?
Is SQL injection a virus or a network break-in?
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 Eduqas GCSE Computer Science topics
How this lesson was checked. This Eduqas GCSE Computer Science (specification C500QS)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 16 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.