UPDATE Statement - SQL Query

Different possible ways to use UPDATE statement.

UPDATE statement is used to update the records present in the table.

Consider the following table 'Students'.  

StudentidFirstnameLastnameEmailPhone
1JayaSinghJaya@tutorialride.comnull
2ShrutiShrabyaShruti@tutorialride.comnull

i) Update only one field.

Update the column Phone where condition is given as Stud_id = 1

ii) Update multiple fields.

Such as F_name, L_name, Phone where condition is given as Stud_id= 2

To update column Phone where Stud_id= 1 the query should be written as:

UPDATE Students SET Phone = 34542892 WHERE Stud_ID = 1


Note: The 'SET' specifies the variable names to be updated.

Result:

StudentidFirstnameLastnameEmailPhone
1JayaSinghJaya@tutorialride.com34542892
2ShrutiShrabyaShruti@tutorialride.comnull

So to update multiple fields where Stud_id= 2.

The query should be written as:

UPDATE Students SET F_name = 'Surendra', L_name = 'Morya', Phone = 92384900, email = 'Surendra@tutorialride.com' WHERE Stud_ID = 2;


Result:

StudentidFirstnameLastnameEmailPhone
1JayaSinghJaya@tutorialride.com34542892
2SurendraMoryaSurendra@tutorialride.com92384900