AQA GCSE CSPaper 2 · Unit 7Lesson 8

Paper 2 · Unit 7 · CS-L7-08

SQL: INSERT INTO

60 minutes · AQA 8525 · Paper 2 — Relational databases & SQL

Spec & Goals 3 min

AQA Spec 3.7.2 — Inserting data with INSERT INTO … VALUES

By the end of this lesson you can:

  1. Use INSERT INTO … VALUES to add a new record.
  2. Match values to the correct fields, quoting text and dates.
  3. Spot and fix common INSERT errors.

Warm-Up 5 min

So far every query read data. SQL can also add data. A new student joins — how do we put their record into the table?

Quick starter

To add a row, what two things must you give the database — and in what order?

Reveal the idea

The fields and the matching values, in the same order: INSERT INTO Student (…fields…) VALUES (…values…);

Key Concept — adding a record 14 min

INSERT INTO tableName (field1, field2, field3)
VALUES (value1, value2, value3);
  • List the fields you are filling, then the values in the same order.
  • Text and dates go in single quotes ('Lina'); numbers do not (107).
  • The number of values must match the number of fields.
  • The primary key value must be unique and not already used.

Before

StudentIDNameFormTownMark
105Mei Ling11CPenang88
106Hafiz10BKuala Lumpur72

Insert a new student

INSERT INTO Student (StudentID, Name, Form, Town, Mark)
VALUES (107, 'Lina', '10A', 'Melaka', 83);

After

StudentIDNameFormTownMark
105Mei Ling11CPenang88
106Hafiz10BKuala Lumpur72
107Lina10AMelaka83

Worked Example — write and debug 12 min

Part 1 — write it: add product 12, "Teh Tarik", RM 2.50, category "Drinks" to Product(ProductID, ItemName, Price, Category).

INSERT INTO Product (ProductID, ItemName, Price, Category)
VALUES (12, 'Teh Tarik', 2.50, 'Drinks');

Part 2 — find the errors in this attempt:

INSERT INTO Product (ProductID, ItemName, Price)
VALUES (13, Roti Canai, '1.20', 'Food');
  • Three fields are listed but four values are given — counts don't match.
  • Roti Canai is text but has no quotes.
  • '1.20' is a number wrongly written in quotes.

Corrected:

INSERT INTO Product (ProductID, ItemName, Price, Category)
VALUES (13, 'Roti Canai', 1.20, 'Food');

Try It Yourself 12 min

🟢 Easy

Goal: Write an INSERT to add student 108, "Arif", form "10B", town "Ipoh", mark 69.

🟡 Medium

Goal: Explain why VALUES (108, Arif, 10B, Ipoh, 69) would fail.

Hint: which values are text?

🔴 Stretch

Goal: A new INSERT reuses StudentID 103. Explain why this should be rejected.

📝 Exam Practice 10 min

Write a program[3 marks]

Write an SQL statement to add a new student to the Student table: ID 109, name Suresh, form 11C, town Penang, mark 76.

Mark scheme
  • INSERT INTO Student (StudentID, Name, Form, Town, Mark) (1).
  • VALUES (109, 'Suresh', '11C', 'Penang', 76); — correct values in order (1).
  • Text values quoted, numbers unquoted (1).
Identify[2 marks]

Identify two errors in: INSERT INTO Student (StudentID, Name) VALUES ('110', Tan, '10A');

Mark scheme
  • Two fields listed but three values given (1).
  • '110' is a number but quoted / Tan is text but not quoted (any one) (1).
Explain[1 mark]

Explain why an INSERT using an existing primary-key value should be rejected.

Mark scheme
  • The primary key must be unique; a duplicate would break that / records could not be told apart (1).

Recap & Key Terms 3 min

INSERT INTO table (fields) VALUES (values); adds a record. Values must match the fields in number and order; quote text and dates, not numbers; the primary key must be unique. AQA assesses SELECT/WHERE/ORDER BY and INSERT only.

INSERT INTO
The SQL command that adds a new record to a table.
VALUES
The list of data, in field order, for the new record.
Quoting rule
Text and dates go in single quotes; numbers do not.

Homework 1 min

Task (≤ 15 min): A library adds a new member: MemberID 220, name "Devi", town "Ipoh", joined '2026-06-05'. Write the INSERT, then list two rules your statement obeys.

Model answer
INSERT INTO Member (MemberID, Name, Town, JoinDate)
VALUES (220, 'Devi', 'Ipoh', '2026-06-05');

Rules obeyed: text and the date are in single quotes, the number is not; the number of values matches the fields and is in the same order; MemberID 220 is unique.

Award marks for: correct INSERT structure (1); correct quoting (1); two valid rules stated (1).