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
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.
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'