Menu

SQL Update – Mastering SQL Update with Examples

Dive deep into one of the most commonly used SQL commands - UPDATE. It is used to modify existing records in a table and is a crucial part of database management and maintenance.

Written by Jagdeesh | 2 min read

Let’s dive deep into one of the most commonly used SQL commands – UPDATE. The UPDATE statement is used to modify existing records in a table and is a crucial part of database management and maintenance.

SQL UPDATE Syntax

The basic syntax for the SQL UPDATE command is as follows

sql
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

Now, let’s look at a few practical examples.

SQL UPDATE in Action

Sample Data

For our examples, let’s use a simple table named Employees

sql
CREATE TABLE Employees (
    EmpID INT,
    EmpName VARCHAR(50),
    EmpEmail VARCHAR(50),
    Salary FLOAT,
    Department VARCHAR(30)
);

And we’ll insert some data

sql
INSERT INTO Employees (EmpID, EmpName, EmpEmail, Salary, Department)
VALUES 
    (1, 'John Doe', 'jdoe@example.com', 50000, 'HR'),
    (2, 'Jane Smith', 'jsmith@example.com', 60000, 'IT'),
    (3, 'Bob Johnson', 'bjohnson@example.com', 70000, 'Sales'),
    (4, 'Alice Williams', 'awilliams@example.com', 55000, 'HR');

Our Employees table now looks like this

output
EmpID | EmpName       | EmpEmail             | Salary | Department
------|---------------|----------------------|--------|------------
1     | John Doe      | jdoe@example.com     | 50000  | HR
2     | Jane Smith    | jsmith@example.com   | 60000  | IT
3     | Bob Johnson   | bjohnson@example.com | 70000  | Sales
4     | Alice Williams| awilliams@example.com| 55000  | HR

1) Basic UPDATE

Jane Smith from the IT department has been given a raise, and her new salary is 65000.

Here’s how we would update her record

sql
UPDATE Employees
SET Salary = 65000
WHERE EmpID = 2;

Jane’s record in the Employees table would now be

output
EmpID | EmpName   | EmpEmail           | Salary | Department
------|-----------|--------------------|--------|------------
2     | Jane Smith| jsmith@example.com | 65000  | IT

2) Updating Multiple Columns

Alice Williams has been promoted and moved to the IT department with a new salary of 70000.

We can update her record like this

sql
UPDATE Employees
SET Salary = 70000, Department = 'IT'
WHERE EmpID = 4;

Alice’s updated record

output
EmpID | EmpName      | EmpEmail              | Salary | Department
------|--------------|-----------------------|--------|------------
4     | Alice Williams | awilliams@example.com | 70000  | IT

3) UPDATE With a Subquery

Suppose the company decides to give a 10% raise to everyone in the HR department.

Instead of updating each record individually, we can use a subquery

sql
UPDATE Employees
SET Salary = Salary * 1.1
WHERE Department = 'HR';

The updated Employees table

output
EmpID | EmpName       | EmpEmail             | Salary | Department
------|---------------|----------------------|--------|------------
1     | John Doe      | jdoe@example.com     | 55000  | HR
2     | Jane Smith    | jsmith@example.com   | 65000  | IT
3     | Bob Johnson   | bjohnson@example.com | 70000  | Sales
4     | Alice Williams| awilliams@example.com| 70000  | IT

Key Takeaways

Remember the following points when working with SQL UPDATE:

Always ensure you use a WHERE clause with your UPDATE statement.
– If you don’t, you’ll update all rows in the table.
– Be careful when using subqueries. They’re powerful but can also be tricky.
– Always backup your data before running an UPDATE statement. This will protect you from unintended changes.

Free Course
Master Core Python — Your First Step into AI/ML

Build a strong Python foundation with hands-on exercises designed for aspiring Data Scientists and AI/ML Engineers.

Start Free Course
Trusted by 50,000+ learners
Jagdeesh
Written by
Related Course
Master SQL — Hands-On
Join 5,000+ students at edu.machinelearningplus.com
Explore Course
Wait — don't leave
without your free
AI/ML Roadmap

The step-by-step path used by 25,000+ learners to go from zero to career-ready in AI/ML.

Please fill in your name and a valid email.
🔒 100% Free ☕ No spam, ever ✓ Instant delivery

Roadmap sent to your inbox!

Can't find it? Check your spam or promotions tab.

Not sure where to start?

Book a free 15-min call — our team will map out the right path for your background. Zero sales pressure.

📞

Request a free callback

Team available · 15 min · No commitment

🇮🇳 +91
🇮🇳 India +91
🇺🇸 USA +1
🇬🇧 UK +44
🇦🇺 AUS +61
🇦🇪 UAE +971
🇸🇬 SG +65
🇲🇾 MY +60
🇵🇰 PK +92
🇧🇩 BD +880
🇳🇵 NP +977
🇱🇰 LK +94
🇫🇷 FR +33
🇩🇪 DE +49
🇮🇹 IT +39
🇪🇸 ES +34
🇳🇱 NL +31
🇸🇪 SE +46
🇨🇭 CH +41
🇵🇱 PL +48
🇹🇷 TR +90
🇸🇦 SA +966
🇶🇦 QA +974
🇰🇼 KW +965
🇴🇲 OM +968
🇧🇭 BH +973
🇪🇬 EG +20
🇿🇦 ZA +27
🇳🇬 NG +234
🇰🇪 KE +254
🇬🇭 GH +233
🇨🇳 CN +86
🇯🇵 JP +81
🇰🇷 KR +82
🇮🇩 ID +62
🇵🇭 PH +63
🇧🇷 BR +55
🇲🇽 MX +52
🇦🇷 AR +54
🇨🇦 CA +1
🇳🇿 NZ +64
🇮🇪 IE +353
Please enter your phone number.

Thank you for your submission!

Our team will call you shortly. You'll also receive a confirmation on your email.

Scroll to Top
Scroll to Top
Course Preview

Machine Learning A-Z™: Hands-On Python & R In Data Science

Free Sample Videos:

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science