SQL UPDATE Query - SQL UPDATE Statement

Video Tutorial
FREE
 UPDATE , DELETE  thumbnail
This video belongs to
DBMS Course - Master the Fundamentals and Advanced Concepts
16 modules
Certificate
Topics Covered

Overview

The update command is a DML command used to update a table's records. The SET keyword is used in the update command. The WHERE clause is also used in the update command for updating single or multiple columns of the table.

Introduction to Update Query in SQL

The update command is a DML command that works on the records of a particular database table. The primary function of the update query in SQL is to update single or multiple records of the table.

Let's understand the syntax for updating queries in SQL.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Syntax for Update in SQL

The update command takes tableName and a set keyword for updating the table's records. We can also use the while clause in the update command. That's why we can update multiple records at the same time.

Syntax:

SQL UPDATE Statement Examples

You may want to update a particular student's name in the table. You have two options: delete the old record from the table and insert the updated record, but there are more efficient approaches. We will take the update query to update the name of the student.

Consider the table below.

TableName: Student

AdminNoNameMarksClass
101Aayush105
102Amit115
97Sourav126

Updating Name of the Student

Let's say you want to change the name of the student Amit to Amit Sharma. To update the record, we will use the update query.

Let's understand how to update the name

Syntax

We will take the help of the AdminNo to fetch the desired record from the table. Because the AdminNo is unique, the update command will fetch only a single record if it is present.

Check out this SQL Tutorial to learn more about SQL in depth.

UPDATE One Column

Updating one column means changing the value of a particular column for specific or multiple records.

Let's understand how to update one column using the update DML command.

Consider the below table.

TableName: Student

AdminNoNameMarksClass
101Aayush105
102Amit115
97Sourav126

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Updating Name of the Student

Suppose you want to change the name of the student Sourav to Sourav Sharma. To update the record, we will use the update query.

Let's understand how to update the name

Syntax

We will take the help of the AdminNo to fetch the desired record from the table. Because the AdminNo is unique, the update command will fetch only a single record if it is present.

UPDATE Multiple Columns

Updating multiple columns means changing the value of multiple columns for specific or multiple records.

Let's understand how to update multiple columns using the update DML command.

Consider the below table.

TableName: Student

AdminNoNameMarksClass
101Aayush105
102Amit115
97Sourav126

Updating Name of the Student

You want to change the name of the student Sourav to Sourav Sharma as well as update the marks of the student. To perform this task, we will use the update query.

To update the name and marks, we can use the following query:

UPDATE Multiple Rows

We can update the multiple rows of the table using the single update command. Let's understand how to update the multiple rows of the table.

Consider the below table:

TableName: Student

AdminNoNameMarksClass
101Aayush105
102Amit115
97Sourav126

If we want to update the class of all the records that belong to class 5 to class 6, we can use the following query:

The above query will update the first two rows of the student table.

Conclusion

  • Update query is a DML command.
  • It can be used to update one or many records simultaneously.
  • The SET keyword is used in the update command.
  • Where clause can be used in the update command.
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more