UPDATE Statement
The UPDATE statement modifies existing rows in a table - changing one or more column values for records that match a given condition.
Basic Syntax
UPDATE customers
SET city = 'Gurugram'
WHERE customer_id = 1;
Updating Multiple Columns
UPDATE customers
SET city = 'Gurugram', email = 'riya@example.com'
WHERE customer_id = 1;
The Importance of WHERE
The WHERE clause determines which rows are affected. Leaving it out updates every single row in the table - one of the most common and costly mistakes when writing SQL.
-- Dangerous: updates ALL rows in the table!
UPDATE customers
SET city = 'Gurugram';
Before running an UPDATE with a new WHERE condition, it's good practice to first run the same condition as a SELECT statement to confirm exactly which rows will be affected.