How to use the basic syntax of the SQL update statement.
The update statement is used to modify existing data in the database. Here is the basic syntax for using the update statement:
UPDATE 表名
SET 列名1 = 值1, 列名2 = 值2, ...
WHERE 条件;
The table name indicates which table the data is being updated in, the column name specifies which column is being updated, the value represents the new value being updated, and the condition determines which rows are being updated.
Important notes:
- If the WHERE clause is not used, the update statement will modify all rows in the table.
- If the WHERE clause is used, only the rows that meet the condition will be updated.
- When updating multiple columns, separate the update statements for each column with commas (,).
- The SET clause is used to specify the columns to be updated and their new values.
- The order of update statements is to first specify the table to update, then the SET clause, and finally the WHERE clause.
Here is an example demonstrating how to use the update statement to update data in a table:
Assuming we have a table named “students” with columns “name” and “age”, if we want to update the age of the student named “Zhang San” to 20 years old, we can use the following statement:
UPDATE students
SET 年龄 = 20
WHERE 姓名 = '张三';
This will update the age of the student named “Zhang San” in the table to 20 years old.