How to Update

The update SQL statement allows the user to modify the content of any existing record in a table. It basically has two clauses:

  • The set clause is used to define the new value to put into the column (or columns) to be updated.
  • The where clause is used to specify what are the rows to update. We can modify just one row of the table, a subset of rows, or we can modify all the records of the table.
-- John Smith receives a rise of 5000

Update employee set salary = salary + 5000 
where last_name = ‘Smith’ and first_name = ‘John’;

-- All employees with a NULL in last_name are set with a 
-- generic value 'No Last name'.

Update employee set last_name = 'No Last Name' 
where last_name IS NULL;