How to update multiple records at once in MySQL?
In MySQL, you can use the UPDATE statement to update multiple records at once. The WHERE clause can be used to specify the conditions of the records that need to be updated.
Here is an example demonstrating how to update multiple records at once:
UPDATE 表名
SET 列名1 = 新值1, 列名2 = 新值2
WHERE 条件;
The table name refers to the name of the table to be updated, column1 and column2 refer to the names of the columns to be updated, newValue1 and newValue2 are the new values to be updated to, and the condition specifies the records to be updated.
For example, suppose there is a table called students, which includes columns for id, name, and age. Now, to change the names of all students under the age of 18 to “Minor”, you can use the following statement:
UPDATE students
SET name = '未成年'
WHERE age < 18;
This way, the names of all students under the age of 18 will be updated to “minor”.