⚡ 180+ new openings posted today

SQL UPDATE Statement

What is the UPDATE Statement in SQL ?

Answer : The SQL UPDATE statement is used to modify the existing records in a table. We can update single columns as well as multiple columns using UPDATE statement as per our requirement. We can use the WHERE clause with the UPDATE query to update the selected rows, otherwise all the rows would be affected.

Syntax

If you want to update a single record :

UPDATE table_name
SET column_name = value
WHERE condition;

We can update multiple columns in a single UPDATE statement by separating each column with a comma.

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

You can combine N number of conditions using the AND or the OR operators.

Example

Suppose we have an Employees table:

Employee_IDEmployee_NameSalary
101Anjali50000
102Priya45000
103Amit55000

If we want to update Priya’s salary to 5000

UPDATE Employees
SET Salary = 5000
WHERE Employee_Name = ‘Priya’;

After Update

Employee_IDEmployee_NameSalary
101Anjali50000
102Priya5000
103Amit55000

If we want to update Priya’s name and salary:

UPDATE Employees
SET Employee_Name = ‘Priyanka’,
Salary = 60000
WHERE Employee_ID = 102;

After Update

Employee_IDEmployee_NameSalary
101Anjali50000
102Priyanka60000
103Amit55000

Leave a Comment

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

Scroll to Top