How to Update

The update SQL statement allows the user to modify the content of any existing record in a table. It has basically 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 emp_id receive a new emp_id value 
-- obtained with a function.

Update employee set emp_id = next_emp_id() 
where emp_id IS NULL;

IN THIS PAGE