In this tutorial, we will learn how to UPDATE
records into a table of a database using SQL.
UPDATE
statement is used to update/modify the existing record in a table.UPDATE
statement can update one or more records in a table.WHERE
clause to update/modify only specific records otherwise all records of selected columns updated.UPDATE tableName
SET column1 = value1, column2 = value2,...columnN=valueN
WHERE [CONDITION]
Let us consider this table "Employee" for records.
Table Name: Employee
ID | EmpName | City | Country | Gender | Salary |
1 | Shankar | Delhi | India | male | 25000 |
2 | Sourabh | Delhi | India | male | 30000 |
3 | Ranvijay | Mumbai | India | male | 15000 |
4 | Kapil | Noida | India | male | 25000 |
5 | Shalini | Jaipur | India | female | 18000 |
6 | Rakesh | Faridabad | India | male | 23000 |
7 | Akshay | Mumbai | India | male | 21000 |
8 | Sarah | New York | US | female | 76000 |
9 | Rocky | Noida | India | male | 28000 |
For Updating Salary of ID=3 in a table "Employee", a query will be:
UPDATE Employee
SET Salary = 16000
WHERE ID=3
Now if we SELECT
this record, we can see the updated value
--For Selecting Updated Record,query will be
SELECT * FROM Employee WHERE ID=3
ID | EmpName | City | Country | Gender | Salary |
3 | Ranvijay | Mumbai | India | male | 15000 |
For Updating "City" and "Salary" of ID=3 in a table "Employee", a query will be:
UPDATE Employee
SET City = 'Chennai', Salary= 18000
WHERE ID=3
ID | EmpName | City | Country | Gender | Salary |
3 | Ranvijay | Chennai | India | male | 18000 |