GCSE · Computer Science · AQA · Spec 8525
SQL INSERT INTO
A table is waiting for a new record. Two bracketed lists decide exactly where every value lands, and one small slip puts the right data in the wrong place.
Computer Science · Databases
INSERT INTO: watch each value find its field
Press Next to run the statement one value at a time. The table on the right is the table's contents.
Before you press Next: the statement has three values and three fields. Which field do you think the 12 will land in?
INSERT INTO tblLessons (LessonID, CourseID, MemberID) VALUES (4, 12, 203);
Result
| LessonID | CourseID | MemberID |
|---|---|---|
| 1 | 10 | 201 |
| 2 | 10 | 202 |
| 3 | 11 | 201 |
Output
Step 1: This is tblLessons before the statement runs: three records, three fields. The statement has not run yet, so nothing has changed.
Step through the trace — every value is the lesson’s, not run by the page.
Computer Science · Databases
Accepted or rejected?
tblLessons already holds LessonID 1, 2 and 3. LessonID is a PRIMARY KEY and CourseID is NOT NULL. Will each INSERT be accepted or rejected, and why?
Still to sort
Accepted (0)
Breaks no rule.
Where the line is: If every rule is kept, the record goes in.
Rejected (0)
Breaks at least one rule.
Where the line is: One broken rule is enough: the table refuses the record.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Two bracketed lists, lined up side by side. Work out where every value lands, then see what happens when the table says no.
What you need to know
- SQL (structured query language) manages data in relational databases, and its statements must follow syntax rules to execute correctly.
- An INSERT statement adds data into a table that already exists.
- Start with INSERT INTO, then the table name, then the field names in brackets, separated by commas.
- On the next line, write VALUES, then the values, also in brackets and separated by commas.
- Order is everything: values go in the same order as the field names, so each lands in its matching field.
Have a goSam says: "SQL is clever, it will spot that 203 is obviously a member number." The fields are (LessonID, CourseID, MemberID) and Sam writes VALUES (203, 4, 12). Where does 203 really go?
Into LessonID, because it is the first value.
SQL matches by position only. It never judges a value by how it looks, so Sam's 203 lands in the first field.
- CREATE TABLE makes a new table first: the table name, then the fields with their data types in brackets.
Have a goYour friend has a brand new idea for a table that does not exist yet. Which do you run first: INSERT INTO or CREATE TABLE?
CREATE TABLE.
A table must exist before records can be inserted, so the table comes first and the records second.
- Constraints are rules the data must follow. NOT NULL means a column will not accept a null value.
- PRIMARY KEY means every row has a unique, non-null value in that column.
Have a goA column is a PRIMARY KEY. A record arrives with no value at all in that column. Can the table accept it?
No. A primary key needs a value in every row.
Primary key means unique and non-null, so a row with nothing in that column breaks the rule.
- Break a rule and the INSERT is rejected.
- A foreign key is a value that exists as a primary key in another table.
The big picture
SQL manages data in relational databases. An INSERT statement adds a record to a table that already exists: INSERT INTO, the table and its field names in brackets, then VALUES and the values in brackets, in the same order as the fields. The table has to be made first with CREATE TABLE, and constraints such as NOT NULL and PRIMARY KEY make the table reject any INSERT that breaks its rules.
Key points
Worked example
Problem
Work out the record that this statement adds to tblLessons: INSERT INTO tblLessons (MemberID, LessonID, CourseID) VALUES (206, 9, 13);
⚠ Watch out
Thinking SQL works out which value belongs in which field, or that a table accepts any data. It does not: values are matched to fields by position only, and constraints such as PRIMARY KEY and NOT NULL make the table reject rows that break its rules.
Memory hook
Field names on top, values underneath, like pegs lined up with labelled holes: the first peg goes in the first hole, whatever the peg looks like. And the constraints are the doorman: break a rule and the record does not get in.
Check yourself
Cover the page. Write the two lines of an INSERT for a record of your own in tblLessons, then say which value lands in the second field and one rule an INSERT could break.
Flashcards
(11)What is SQL used for?
What does an SQL INSERT statement do?
What is the basic shape of an INSERT statement?
How does SQL decide which value goes into which field?
What goes wrong if two values in the VALUES line are swapped?
Which statement makes a new table, and what goes in its brackets?
What are INT, FLOAT, CHAR, VARCHAR and DATE examples of?
What does the NOT NULL constraint do?
What does PRIMARY KEY mean for a column?
What happens to an INSERT that breaks a constraint?
What is a foreign key?
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.