UPDATE Statement

Access SQL
  • Syntax
  • Examples
  • Advanced

Syntax:

UPDATE TableName
SET Column = NewValue
WHERE Column = Value;



What does it do?
The UPDATE statement will change the value of a field for one or multiple rows. The WHERE portion of the UPDATE is very important; it will only update the row(s) that match the WHERE constraint, without it all rows in the table will be affected.




Syntax - Multi Column Update:

A comma(,) must be placed in between each column that is being updated, except for the last column.


UPDATE TableName
SET Column = NewValue,
 Column = NewValue
WHERE Column = Value;




Syntax - Update using a join:

UPDATE TableName
INNER JOIN TableName
  ON TableName.Column = TableName.Column
SET TableName.Column = NewValue
WHERE TableName.Column = Value;

Example:

UPDATE Customers
SET LastName = 'Black'
WHERE CustomerID = 1;


Before:

CustomerID FirstName LastName
1 John Doe
2 Jane Doe
3 Jack Jackson
4 Jill Brown


After:

CustomerID FirstName LastName
1 John Black
2 Jane Doe
3 Jack Jackson
4 Jill Brown

Legend

Blue - Is used to identify reserved keywords/characters that are used by the SQL engine, i.e. SELECT, FROM, or WHERE.


Purple - Is used to identify portions of the SQL statement that are defined by the user, i.e. Column Names, Table Names, Inputed Values.