Fundamentals of databases: UPDATE< A-level Computing | AQA | Paper 2 | Fundamentals of databases(Redirected from A-level Computing/AQA/Problem Solving, Programming, Operating Systems, Databases and Networking/Databases/UPDATE)
Database aren't always perfect and there may be times that we want to change the data inside our database. For example in Facebook if someone is annoying you and you limit their access to your profile, you'd update the access field from 'normal' to 'restricted'. Or if one of our crooks gets an additional scar you'd have to update the numScars field. Let's take a look at that example, where our crook Peter gains a scar on his right cheek. This was his initial state:
name: Peter numScars: 7
UPDATE crooks SET numScars = 8
But we have a problem here, this statement updates all records to numScars = 8. This means that every crook will now have 8 scars!
We need to specify which crooks we want to update by using a WHERE clause, you saw it earlier in the SELECT example.
UPDATE crooks SET numScars = 8 WHERE name = "Peter" --only updates those people who are called Peter
UPDATE crooks SET DoB = '17/12/1939' WHERE name = 'Geoff'
UPDATE crooks SET town = 'Canary Wharf'
UPDATE crooks SET DoB = '16/01/1984' ---be careful with dates, they might be using American format WHERE name = 'Sheila' AND gender = 'Female'