To modify one or more existing record, you use the UPDATE statement. To use this command, you state the table to update, the values you want fields to be changed to, and, what records to be changed. For example,
UPDATE Users SET UserName = 'James Smith', Password = 'NEWPASSWORD'
WHERE UserID = 10
In this case, all records which had a UserID of 10 would have their UserName and Password fields changed to the values given. If you only want one record to be updated, you need to ensure that in the WHERE clause, you specify a condition that will only return one record. This would normally be a unique id/primary key field.
Note that you do not have to include all the fields for the record.
If you want to update more than one record, you simply change the condition specified in the WHERE clause. For example,
UPDATE Furniture SET Price = 10 WHERE ItemType = 'Cupboard'
would change the Price field to 10 for all records in the Furniture table where their ItemType field had was "Cupboard".
Comments