Description
The SQL keyword SET is used to assign new column values in an UPDATE statement.
- In order to assign a new value to a column, the column name must be followed by a new value with an equal sign between them.
- In case of multiple columns being updated, each assignment must be separated by a comma.
- Always, make sure to provide a WHERE clause in an UPDATE statement to select the rows to be updated. Otherwise, all the rows are updated.
UPDATE
The below SQL updates the address of a customer.
UPDATE customers
SET address = '123 ABC STREET'
WHERE customer_id = 3;
UPDATE Multiple Columns
The below SQL updates both the country and the city of a customer.
UPDATE customers
SET country = 'France', city = 'Paris'
WHERE customer_id = 3;
UPDATE Multiple Rows
The below SQL updates the city to 'Paris', for all the customers from France.
UPDATE customers
SET city = 'Paris'
WHERE country = 'France';