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 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 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 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 |
What does the UPDATE statement do in SQL?
Adds a new record to the table
Deletes a row from the table
Retrieves data from the table
Modifies existing records in the table
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help
Code Editor
Tables
Execution Result