UPDATE Command in SQL
For Complete YouTube Video: Click Here
In this class, we will understand the UPDATE Command in SQL.
We have already discussed the concepts of the SELECT command.
UPDATE Command in SQL
UPDATE is a Data Manipulation Language DML command.
The UPDATE statement is used to modify the existing records in a table.
UPDATE Command syntax in SQL
The syntax for the update command in the SQL is as shown below.
UPDATE table_name SET column1 = value1, column2 = value2, … WHERE condition;
UPDATE is the keyword.
After the UPDATE, we have to provide the table name in which the updations are to be done.
SET is a keyword.
After SET, we have to provide the column name and the corresponding value in which the updation has to be done.
Next, we have to provide the WHERE condition.
We will try to understand the concept by using the table given below.
In the above table, we will try to update the salary of Vikram from 100 to 600.
The command for the updation is as shown below.
UPDATE students SET salary = 600 WHERE name = ‘Vikram’;
As we have discussed, the SQL will execute row by row.
In our case, the first row will get executed as the name of the student is Vikram.
The image below is the output of the query.
UPDATE without WHERE clause
It is important to check the WHERE clause because if we forget to give the where clause, all the values in the columns will get updated.
This kind of update may produce a disastrous effect.
For example, consider the query without the where clause as shown below.
UPDATE students SET salary = 600;
The image below is the output of the query.
All the 5 rows got updated.