Last updated on May 11th, 2023
Estimated reading time: 2 minutes
SQL UPDATE Syntax
The update statement in SQL is used to update one or more records in Database tables. Update is a DML query. It is commonly used with WHERE clause.
Update specific records based on WHERE condition.
UPDATE tablename
SET column1 = value1, column2 = value2, column2 = value3 ...
WHERE condition;
Update all records with specified value.
UPDATE tablename
SET column1 = value1, column2 = value2, column2 = value3 ...
Database Query Example
If you are new to SQL refer this article. SQL SELECT Statement – Full Stack Tutorials Hub
Select all records from Employee table.
select * from Employee
![select table](https://i0.wp.com/fullstacktutorialshub.com/wp-content/uploads/2023/04/Tab-1.png?resize=1024%2C195&ssl=1)
Update FirstName to “Suresh” where EmployeeId is 4
UPDATE Employee
SET FirstName='Suresh'
WHERE EmployeeId=4;
The output of update values will display number of affected rows. Since only 1 row is updated ,it would display 1 row affected.
Execute select query to display new values.
![select table](https://i0.wp.com/fullstacktutorialshub.com/wp-content/uploads/2023/04/UpdatedValue.png?resize=996%2C158&ssl=1)
Update City=New Mumbai for all employees
The output of update values will display number of affected rows. Since all employees are updated with new value, it would display 4 rows affected.
Execute select query to display new values.
Note: Be very careful to check where condition before executing update query.
UPDATE Employee
SET City='New Mumbai'
![select table](https://i0.wp.com/fullstacktutorialshub.com/wp-content/uploads/2023/04/updatevalues.png?resize=1005%2C156&ssl=1)