UPDATE
The UPDATE statement modifies existing rows in a table. It changes one or more column values for specific rows.
Basic Syntax
The example below shows how to update a record in a table using the UPDATE statement:
UPDATE Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
SETdefines the new values for one or more columns.WHEREspecifies which row(s) should be updated.
Note: Always use a
WHEREclause unless you want to update every row in the table.
Update Statement Example
The query below updates the email for a client named Jason Green.
Update email for a client
UPDATE clients
SET email = 'j.green@newdomain.com'
WHERE name = 'Jason Green';
This updates the email for the client named Jason Green to j.green@newdomain.com.
| id | name | signup_date | |
|---|---|---|---|
| 5 | Jason Green | j.green@newdomain.com | 2023-12-14 |
Update Multiple Columns
The example below shows how to update multiple columns in a table using the UPDATE statement:
Update multiple values at once
UPDATE clients
SET email = 'laura.adams@newdomain.com', signup_date = '2023-04-10'
WHERE id = 4;
This changes both the email and signup date for the client with id = 4.
| id | name | signup_date | |
|---|---|---|---|
| 4 | Laura Adams | laura.adams@newdomain.com | 2023-04-10 |
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.