SQL: Update Statement

Today we’ll be learning about one of the most important statement in SQL that is ‘Update’ statement. As the name says Update statement is used to update the records in the existing table.

Below the table called new_table in database.

1 Table-compressed

 

Update using where clause

Where clause specifies the position on which the update should be done. The SQL query will be as follows and the below image for reference.

Update table_name
set column1= value1, column2=value2,,,,
where column1= value3

 

2 Update-compressed

 

Update using Operators

Update statement can be with SQL operators too. The SQL query will be as follows and below image for reference.

Update table_name
set column1= value1, column2=value2,,,,
where column1= value3 AND/OR (operator) column2=value4

 

3-compressed

 

 

Update using When-Case statement

When-case statement is the if-else condition for SQL and very useful to update records for multiple conditions. The SQL query will be as follows and below image for reference.

update table_name
set column_name
case
when column1=value1 then condition
when column2 =value2 then condition
.
.
.
else condition
end;

 

When Case-compressed

 

This tutorial will give a brief idea about Update statement. I’ll add more tips and tricks to the tutorial.

 

Leave a Reply

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