Description

The SQL keyword UPDATE is used to update records on a database table as mentioned below.

  • Update single column on all or specific set of rows of a table.
  • Update multiple columns on all or a specific set of rows of a table.

Always, make sure to include a WHERE clause in an UPDATE statement to select the records for the update, otherwise all the records are updated.

UPDATE With WHERE Clause

The below SQL updates the salary of an employee (with employee_id = 3) to 50000.

Run this on IDE

UPDATE employees
SET salary = 50000
WHERE employee_id = 3;

UPDATE Without WHERE Clause

The below SQL updates the salary of all the employees (as the WHERE clause is not included) to 50000.

Run this on IDE

UPDATE employees
SET salary = 50000;

UPDATE Multiple Columns

The below SQL updates the name and salary columns of an employee (with employee_id 3) to new values.

Run this on IDE

UPDATE employees
SET salary = 60000, employee_name = 'Andrew Cooper'
WHERE employee_id = 3;

Related Links