Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Suppose we have this table employees
:
id | name | hire_date | salary | |
---|---|---|---|---|
1 | Alice Johnson | alice.johnson@example.com | 2023-01-15 | 60000 |
2 | Bob Smith | bob.smith@example.com | 2021-08-22 | 55000 |
3 | Carol Lee | carol.lee@example.com | 2024-03-10 | 70000 |
Example 1: Update salary for one employee
UPDATE employees
SET salary = 65000
WHERE id = 2;
Note: This command does not produce output.
After the update, the table will look like this:
id | name | hire_date | salary | |
---|---|---|---|---|
1 | Alice Johnson | alice.johnson@example.com | 2023-01-15 | 60000 |
2 | Bob Smith | bob.smith@example.com | 2021-08-22 | 65000 |
3 | Carol Lee | carol.lee@example.com | 2024-03-10 | 70000 |
Example 2: Update email for multiple employees
UPDATE employees
SET email = LOWER(email)
WHERE hire_date < '2023-01-01';
Note: This command does not produce output.
After the update, the table will look like this:
id | name | hire_date | salary | |
---|---|---|---|---|
1 | Alice Johnson | alice.johnson@example.com | 2023-01-15 | 60000 |
2 | Bob Smith | bob.smith@example.com | 2021-08-22 | 65000 |
3 | Carol Lee | carol.lee@example.com | 2024-03-10 | 70000 |
Important Notes:
- The
UPDATE
statement itself returns no data output, only a command status. - To see the changes, run a
SELECT
query after the update.