UPDATE
Published Dec 24, 2024
Contribute to Docs
The UPDATE
statement in SQL is used to modify existing records in a table. This powerful Data Manipulation Language (DML) command allows developers to update one or multiple rows simultaneously.
Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
table_name
: The name of the table containing the data to be updated.SET
: Specifies the columns to update and their new values.condition
: An optional clause that specifies which rows to update. If omitted, all rows in the table are updated.
Example
Let’s say there’s a table Employees
:
ID | Name | Department | Salary |
---|---|---|---|
1 | John | HR | 50000 |
2 | Alice | IT | 60000 |
3 | Bob | Sales | 45000 |
To update Bob’s salary in the Sales department, the following query can be used:
UPDATE EmployeesSET Salary = 47000WHERE Name = 'Bob' AND Department = 'Sales';
Now, the updated table will be as follows:
ID | Name | Department | Salary |
---|---|---|---|
1 | John | HR | 50000 |
2 | Alice | IT | 60000 |
3 | Bob | Sales | 47000 |
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SQL on Codecademy
- Skill path
Analyze Data with SQL
Learn to analyze data with SQL and prepare for technical interviews.Includes 9 CoursesWith CertificateBeginner Friendly17 hours - Free course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner Friendly5 hours