- Test a database using simple SQL queries
- Identify and fix simple errors in records
- Maintain information so it stays accurate
- I can find records that need corrected
- I can use
UPDATEto fix inaccurate information - I can keep before-and-after evidence of my changes
Testing and Maintaining a Database
Testing a database means checking that the structure works and that the stored information is correct. A database can be technically valid but still inaccurate: for example, a bike could have the wrong price, an impossible frame size, or be linked to the wrong type.
Useful test queries
UPDATE ... WHEREFix only the intended recordSELECT proves it is accurateEvidence should show what was wrong, the command used to fix it, and the corrected result.
SELECT * FROM bikes;
SELECT model, price FROM bikes WHERE price > 500;
SELECT model, frame_size FROM bikes WHERE frame_size = 'Small';
SELECT bikes.model, bike_types.type_name
FROM bikes
INNER JOIN bike_types ON bikes.type_id = bike_types.type_id;The final query tests the link between tables. If the wrong type appears beside a bike, the foreign key value may need fixed.
Maintaining accuracy
National 3 specifically requires evidence of keeping information accurate. That means you should show what was wrong, how you corrected it, and the final accurate result.
Practical Evidence
Practical Task 1 - Find and fix errors
Run these commands to add three deliberate errors, then correct them. Keep screenshots or copied output for your evidence.
UPDATE bikes SET price = 78.00 WHERE bike_id = 103;
UPDATE bikes SET frame_size = 'Huge' WHERE bike_id = 101;
UPDATE bikes SET type_id = 2 WHERE bike_id = 103;
-- Test and inspect the records
SELECT * FROM bikes;
-- Correct the errors
UPDATE bikes SET price = 780.00 WHERE bike_id = 103;
UPDATE bikes SET frame_size = 'Medium' WHERE bike_id = 101;
UPDATE bikes SET type_id = 3 WHERE bike_id = 103;
-- Show the corrected data
SELECT * FROM bikes;- Identifies simple errors in the stored information (N3 O1.3)
- Shows the corrected records after using
UPDATE(N3 O1.3) - Explains how the final database has been kept accurate (N3 O1.4)
- Uses a linked query to check that the relationship still works
- Explains why accurate foreign keys matter in a linked structure
- Running
UPDATE bikes SET price = 780.00;without aWHEREclause. That would update every bike. - Only showing the corrected data, with no evidence of what was wrong before.
- Fixing spelling in one place but not checking linked tables.
Task Set
1. Which keyword changes existing records? TYPE 1
2. Why is the WHERE clause important in an update query? TYPE 2
3. Paste your before-and-after evidence for one corrected record. TYPE 3 N3
4. Explain one way you kept the information accurate. TYPE 2 N3
Assessment standards covered: N3 O1.3 and O1.4. This is useful consolidation for N4 but not one of N4's five ISDD standards.