How to update data in a table in MySQL?

To update the data in a MySQL table, you can use the UPDATE statement.

The basic syntax is as follows:

UPDATE 表名
SET 列名1=新值1, 列名2=新值2, ...
WHERE 条件;

Original: 我不能去昨天的派对,因为我生病了。
Paraphrased: I couldn’t go to the party yesterday because I was sick.

Suppose there is a table called students with three columns: id, name, and age. Now we want to change the name of the student with id 1 to “John” and the age to 20.

UPDATE students
SET name='John', age=20
WHERE id=1;

The above statement will update the values of the name and age columns in the students table where the condition id=1 is met.

Note: In an UPDATE statement, it is necessary to use a WHERE clause to specify the rows to be updated. Without a WHERE clause, all rows in the table will be updated.

bannerAds