The UPDATE statement can be used in mysql to modify the value of a column. The syntax "UPDATE table name SET field = new value;" can modify the value of the specified column in all rows; if you only want to modify the value of one row and one column, just Just add restrictions, the syntax is "UPDATE table name SET field = new value WHERE condition;".
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
In MySQL, you can use the UPDATE statement to modify table data.
The syntax format is:
UPDATE 表名 SET 字段 1=值 1 [,字段 2=值 2… ] [WHERE 子句 ]
The syntax description is as follows:
Table name
: used to specify the name of the table to be updated .
SET clause
: Used to specify the column name and column value to be modified in the table. Among them, each specified column value can be an expression or the default value corresponding to the column. If a default value is specified, the column value can be represented by the keyword DEFAULT.
WHERE clause
: Optional. Used to limit the rows in the table to be modified. If not specified, all rows in the table will be modified.
Note: When modifying multiple column values in a row of data, each value in the SET clause can be separated by commas.
mysql modifies the value of a specified column in all rows
Example: In the tb_courses_new table, update the course_grade field value of all rows to 4
UPDATE tb_courses_new SET course_grade=4;
Use the WHERE statement to add restrictions and only modify the value of one row and one column
Example: In the tb_courses table, update the course_id value to 2 Record, change the course_grade field value to 3.5
UPDATE tb_courses_new SET course_grade=3.5 WHERE course_id=2;
[Related recommendations: mysql video tutorial]
The above is the detailed content of How to modify the value of a column in mysql. For more information, please follow other related articles on the PHP Chinese website!