The SQL statement UPDATE can be used to edit or update fields in one, many or all records in a table. These types of queries don’t produce results tables – you have to issue a further SELECT statement to view the results. Here are some examples, using the Employee table:
UPDATE Employee SET Department="MARKETING";
Note that this replaces the Department field for every record. To limit the scope of the update, use the WHERE clause:
UPDATE Employee SET Department="MARKETING" WHERE EmployeeID = 1005;
This performs an update to a single record. In the case where EmployeeID is a primary key, this form of update is guaranteed to modify a single record (at most).
To update several fields at once, list them after the SET keyword. For example, if an employee changed department and got married at the same time:
UPDATE Employee SET Department="MARKETING", LastName = "Pallister" WHERE EmployeeID = 1005;
See also: