- Define and explain Changing Data in your own words
- Use key terms such as table accurately
- Apply what you have learned to new examples and questions
- Avoid the common mistakes learners make with this topic
This lesson focuses on Changing Data: add, update and delete rows safely with INSERT, UPDATE and DELETE.
Add, update and delete rows safely with INSERT, UPDATE and DELETE.
Key ideas
Keys stop data going missing
A primary key guarantees every row can be found exactly once — without one, two customers called 'Smith' become indistinguishable. Foreign keys then link tables: an order row stores the customer's ID rather than copying their whole address, so an address change is updated in one place only. This is the foundation of reliable data.
SQL describes what, not how
You write SELECT Name FROM Students WHERE Year = 12 and the database works out how to find the rows — SQL is declarative. WHERE filters rows, ORDER BY sorts them, and JOIN combines tables via their keys. Because you describe the result you want, the same query works on ten rows or ten million.
Key term — table: A database structure of rows (records) and columns (fields), storing one type of thing — for example, one table per customer, one per order.
Table Students has columns ID, Name, Year with rows (1, Priya, 12), (2, Tom, 11), (3, Aisha, 12), (4, Leo, 10). Write a query listing the names of Year 12 students alphabetically.
We need names only, from the Students table: SELECT Name FROM Students. Keep only Year 12 rows: add WHERE Year = 12. This matches Priya and Aisha. Sort alphabetically: add ORDER BY Name. Aisha comes before Priya. Full query: SELECT Name FROM Students WHERE Year = 12 ORDER BY Name;.
Answer: The query returns two rows: Aisha, then Priya.
- Forgetting the WHERE clause in an UPDATE or DELETE Correction: UPDATE Students SET Year = 13 with no WHERE changes every row — always write the WHERE first, or test with a SELECT using the same condition.
- Storing the same fact in two tables Correction: store it once and link with a foreign key — duplicated data drifts out of sync when only one copy is updated.
Practice
It deletes every row in the table — add a WHERE clause, for example DELETE FROM Students WHERE ID = 4;, to remove only Leo.
False — SQL is declarative: you describe what you want and the database engine decides how to retrieve it.
It is the unique identifier for a row — duplicates or blanks would make it impossible to pinpoint exactly one record.
A foreign key — it stores the primary key of a row in the Customers table, linking each order to its customer.
Quick check
Which of these best defines "table"?
What does this return? SELECT Name FROM Students WHERE Year = 10; using the example table.
Write SQL to show the Title and Author of every book published in 2010 from a Books table.
- Changing Data: add, update and delete rows safely with INSERT, UPDATE and DELETE.
- Keys stop data going missing: A primary key guarantees every row can be found exactly once — without one, two customers called 'Smith' become indistinguishable.
- query: A question asked of a database in SQL — most famously a SELECT statement that retrieves matching rows.
- Watch out for: forgetting the WHERE clause in an UPDATE or DELETE