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

Update command in SQL

In this tutorial section, we will discuss what is an UPDATE query in SQL and how to update records using SQL UPDATE query in a SQL Table with a Demo.

To store data in tables, we use databases. After the data is written to such tables, it is common that you need to update specific fields at some point throughout the data’s lifespan. To do this, we can utilize the UPDATE statement in the SQL language. An Update query is a form of action query that makes several updates to multiple records at once.

Watch this Update Query in SQL video

UPDATE Query in SQL

A Brief Introduction to the 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.

Go for this in-depth job-oriented SQL Training Course now!

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.

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;

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


Also, you can master these queries and become proficient in SQL queries by enrolling in an industry-recognized SQL certification.

Course Schedule

Name Date
SQL Training 2022-05-14 2022-05-15
(Sat-Sun) Weekend batch
View Details
SQL Training 2022-05-21 2022-05-22
(Sat-Sun) Weekend batch
View Details
SQL Training 2022-05-28 2022-05-29
(Sat-Sun) Weekend batch
View Details

Leave a Reply

Your email address will not be published. Required fields are marked *