SQL: Adding and Editing Data
Practise SQL: Adding and Editing Data for GCSE Computer Science with this free worksheet and full mark scheme — Foundation and Higher exam-style questions with worked answers for AQA GCSE Computer Science (8525). Records are changed using INSERT to add, UPDATE to edit and DELETE to remove data.
Free downloads
These worksheets and mark schemes are original, written for Virtus Academy and checked against the current AQA specification. Every worksheet comes with a full mark scheme.
Topic overview
Three SQL statements modify data rather than retrieving it: INSERT adds records, UPDATE changes them, and DELETE removes them.
INSERT INTO names the table and fields, then VALUES supplies the data. Text values need quotation marks and the values must match the fields in order.
UPDATE names the table, SET states the change, and WHERE identifies which records to change. DELETE FROM removes records matching a WHERE condition. The critical point is that omitting WHERE from an UPDATE changes every record in the table, and omitting it from a DELETE removes every record — both irreversible without a backup. Checking the WHERE clause before running either is the habit worth building.
Revision notes
INSERT
INSERT INTO names the table and the fields, and VALUES supplies the data.
INSERT INTO Students (Name, Age) VALUES ('Amir', 15). Text needs quotation marks; the values must match the fields in order.
UPDATE
UPDATE names the table, SET states the change, WHERE identifies which records.
UPDATE Students SET Age = 16 WHERE StudentID = 3 changes one record. Without the WHERE clause, every record in the table would be changed.
DELETE and the WHERE warning
DELETE FROM Students WHERE StudentID = 3 removes one record.
DELETE FROM Students with no WHERE clause removes every record in the table. The same applies to UPDATE. Both are irreversible without a backup, so the WHERE clause should always be checked before running.
Key points
- INSERT adds new records.
- UPDATE changes existing records.
- DELETE removes records.
- VALUES must match the fields in order.
- UPDATE without WHERE changes every record.
- DELETE without WHERE removes every record.
Worked examples
Example 1
Write an SQL statement adding a record with Name 'Amir' and Age 15 to Students. [3 marks]
Working
Example 2
Write a statement changing the Age to 16 for the student with StudentID 3. [3 marks]
Working
Example 3
Explain why omitting the WHERE clause from a DELETE statement is dangerous. [2 marks]
Working
Common mistakes
Omitting WHERE from UPDATE or DELETE.
Every record in the table is affected.
Mismatching fields and values.
They must correspond in order and in number.
Quoting numbers.
Only text values need quotation marks.
Confusing UPDATE with INSERT.
INSERT adds a new record; UPDATE changes an existing one.
Exam tips
- Always include a WHERE clause on UPDATE and DELETE.
- Match values to fields in order.
- Quote text but not numbers.
- Check the WHERE clause before running the statement.
Key terms
- INSERT
- The statement adding a new record.
- UPDATE
- The statement changing existing records.
- DELETE
- The statement removing records.
- SET
- The clause stating what an UPDATE changes.
Related topics
Written and reviewed against the current AQA specification. Spotted an error? Let us know.