• Articles
  • Tutorials
  • Interview Questions

UPDATE Query in SQL

Tutorial Playlist
Reviewed and fact-checked by
7.1K+
career-aspirant learners have read this article
Reviewed and fact-checked by
Sahil Ambardar
Data Engineer

SQL UPDATE Query

The SQL UPDATE query is used to modify existing records in a database table. It allows changing the values stored in one or more fields of selected records without replacing the entire record. The basic structure includes specifying the table name, field(s) to update, new value(s) to replace old ones, and a condition in the WHERE clause to identify which record(s) to update. 

SQL UPDATE query provides a convenient way to keep data up-to-date by correcting mistakes, adding or removing information, and modifying values directly in the database table.

Watch this Update Query in SQL video

How to Use UPDATE Query in SQL?

The UPDATE command in SQL is used to modify or change the existing records in a table. If we want to update a particular value, we use the WHERE clause along with the UPDATE clause. If you do not use the WHERE clause, all the rows will be affected. Moreover, we can use the UPDATE statement to update single or several columns depending on our needs.

Syntax

UPDATE table_name
SET col1=val1, col2=val2…
[Where condition];

where UPDATE, SET, and WHERE are the keywords, table_name is the name of the table you want the update, col1, col2, … are the columns considered to be updated, val1, val2, … assign new values, and the condition section is where the condition is given, followed by a semicolon.

Let’s update some records of the employee table using the Update command in SQL

UPDATE employee
SET e_age=42
WHERE e_name=’sam’;

Get 100% Hike!

Master Most in Demand Skills Now !

Update Table in SQL

  • After writing the query, click on the execute button to check for errors

A Brief Introduction to the UPDATE Statement

  • Once the query is executed, a message appears like ‘Commands completed successfully’
  • Let’s check the update

SELECT * from employee;

A Brief Introduction to the UPDATE Statement step 2

  • Now you can check out the updated data in the table.

Also, Check our blog on Replace in SQL: Usage and Implementation of REPLACE() Function.

SQL Update Multiple Columns

Here is an example for updating multiple columns in SQL.

UPDATE EMPLOYEE
SET Last_Name='KAPADIA',First_Name='MANISH'
WHERE Employee_ID=7369
  • After writing the query, click on the execute button to check for errors
  • Once the query is executed, a message appears like ‘1 row affected ‘.

SQL Update Multiple Columns

  • Let’s check the update

Enroll yourself for SQL certification and give a head-start to your career in SQL!

Become a Database ArchitectSELECT * from employee;

  • Now you can check out the updated data in the table.

data in the table

Do you still have queries? Come to Intellipaat’s SQL Community, clarify all your doubts, and excel in your career!

SQL Update Multiple Rows

UPDATE Employee
SET Middle_Name 
= CASE Employee_ID
WHEN 7369 THEN 'A'
WHEN 7499 THEN 'B'
ELSE Middle_Name
END
WHERE Employee_ID IN(7369,7499);
  • After writing the query, click on the execute button to check for errors
  • Once the query is executed, a message appears like ‘1 row affected ‘.

row affected

  • Let’s check the update
  • SELECT * from employee;

Know the most common methods for executing function in sql by exploring our blog on how to run function in SQL!

select the employee

This brings us to the end of this tutorial section, and you’re ready for updating your database with the Update query in SQL.

Wish to crack SQL interviews? Intellipaat’s Top SQL Interview Questions are meant only for you!

Course Schedule

Name Date Details
SQL Training 22 Jun 2024(Sat-Sun) Weekend Batch
View Details
SQL Training 29 Jun 2024(Sat-Sun) Weekend Batch
View Details
SQL Training 06 Jul 2024(Sat-Sun) Weekend Batch
View Details

About the Author

Technical Manager - DevOps

Akshay Shukla, a Technical Manager in DevOps, is an experienced professional with a rich background in Cloud Computing, Software Development, and Talent Acquisition. Proficient in Azure, Kubernetes, Docker, and more, he excels at designing scalable solutions and automating workflows. He leads his team with unwavering commitment and also has a passion for crafting business content.