UPDATE
The UPDATE statement allows you
to modify existing data in a database. There are three clauses to the basic
UPDATE statement:
UPDATE tablename
SET field1=value1,
field2=value2...
WHERE condition1,
condition2
The WHERE clause is optional,
but should not be omitted unless you deliberately intend to update all rows
in a table. The WHERE clause determines which rows in the table should be
updated, while the SET clause specifies which columns should be updated and
the values to set them to.
The UPDATE clause specifies the
table to be updated. Only one table can be updated at a time. The following
example demonstrates how to use the UPDATE statement:
Example:
UPDATE
tblAddressBook
SET
Address = '23 London
Street, London',
PostCode = 'L99 9ZZ'
PhoneNumber = '0976
543 210'
WHERE
Name = 'Stephen
Smith'
In this example, Stephen
Smith's address and phone number are updated. If the WHERE clause had been
omitted, then all rows in the table would have had their address and phone
number updated to the above values.
In the SET clause, the new
values for the fields can also be specified by looking up fields from other
tables, or from an expression. For example, to update the age column the
following expression can be used in the SET clause.
Example:
UPDATE
tblAddressBook
SET
Age = Age + 1
WHERE |