Here are the topics we are about to discuss in this blog:

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!

Career Transition

Got Job With Salary Hike | Process Developer to Sr. Software Engineer Career Transition
Got Multiple Job Offers with 100% Salary Hike | Best SQL Course | Intellipaat Career Transition
How To Switch Career From A Support Role To Oracle DBA Engineer | Got Job With 80% Salary Hike
How To Become A Database Expert From A Non Tech Background | Got Job With Salary Hike | Intellipaat
Got Job as Cloud DBA Just After completion of the Course | Intellipaat Career Transition
SQL Developer to Software Engineer Career Transition | Got Job with 120% Salary Hike | Intellipaat

Course Schedule

Name Date Details
SQL Training 23 Mar 2024(Sat-Sun) Weekend Batch
View Details
SQL Training 30 Mar 2024(Sat-Sun) Weekend Batch
View Details
SQL Training 06 Apr 2024(Sat-Sun) Weekend Batch
View Details