How can multiple records be updated at once in MySQL using the update statement?
In MySQL, you can use the UPDATE statement to modify multiple records at once. Here is an example:
Assume there is a table named “students” that includes the following fields:
We now want to increase the ages of all students by 1 year. This can be achieved using the following UPDATE statement:
UPDATE students SET age = age + 1;
After executing this statement, the data in the students table will be changed to:
This will update the age of all students at once. Please note, if you want to update specific data, you can use a WHERE clause to limit the scope of the update, for example:
UPDATE students SET age = age + 1 WHERE name = 'Alice';
After executing this statement, only the age of the student named Alice will increase by 1 year. The data of other students will remain unchanged.