SQL UPDATE QUERY - The Coding Shala
Home >> Learn SQL >> SQL UPDATE Query
The following query will update 'PersonID' = 2 if 'LastName' is "last" -
Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.
SQL UPDATE QUERY
SQL 'UPDATE' Query is used to modify the existing record in the table. We generally use 'UPDATE' with the 'WHERE' to specify the certain row, if we miss the where condition then all the rows would be affected.
SQL UPDATE Query Syntax
The basic SQL UPDATE query syntax is as follows -
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
SQL UPDATE Query Examples
The following table 'Persons' contains -
PersonID LastName FirstName Address City 1 Saini Akshay A-101 Pune 1 last first A-101 Pune 2 null Akshay null null
The following query will update 'PersonID' = 2 if 'LastName' is "last" -
SQL >> update Persons set PersonID = 2 where LastName = "last" Output >> PersonID LastName FirstName Address City 1 Saini Akshay A-101 Pune 2 last first A-101 Pune 2 null Akshay null null
- Like this, we can update more than one columns -
SQL >> update Persons set PersonID = 3, FirstName = "Nikhil" where LastName is null Output >> PersonID LastName FirstName Address City 1 Saini Akshay A-101 Pune 2 last first A-101 Pune 3 null Nikhil null null
Other Posts You May Like
Prev<< SQL SELECT Query NEXT >>SQL Delete Query
Comments
Post a Comment