📅  最后修改于: 2023-12-03 15:20:15.874000             🧑  作者: Mango
SQL Update statement is used to modify or update existing records in a database table. It is part of Data Manipulation Language (DML). The update statement can modify one or more columns in a table, and it can update one or many rows depending on the Where clause.
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Suppose we have a table called employees
with the following data:
| id | name | age | department | salary | |----|------|-----|------------|--------| | 1 | John | 30 | HR | 50000 | | 2 | Jane | 25 | IT | 60000 | | 3 | Mark | 35 | Finance | 70000 | | 4 | Mary | 40 | HR | 55000 |
UPDATE employees
SET salary = 65000
WHERE name = 'John';
This query updates the salary of John to 65000.
UPDATE employees
SET age = 27, department = 'Marketing', salary = 56000
WHERE id = 2;
This query updates the age, department, and salary of the employee with id 2.
UPDATE employees
SET salary = 60000
WHERE department = 'HR';
This query updates the salary of all employees in the HR department to 60000.
In conclusion, the SQL Update statement is used to modify existing data in a database table. It is a powerful tool that can update one or more columns, and one or many rows at a time. It is an essential part of SQL DML and can be used to keep data up to date and accurate.