UPDATE
The UPDATE
statement is used to modify existing records in a table. It lets you change the value of one or more columns 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;
SET
defines the new values for one or more columns.WHERE
specifies which row(s) should be updated.
Always use a WHERE clause 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's Next?
Next, you'll learn how to remove records from a table using the DELETE
command.
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