Home > Database > Mysql Tutorial > How to modify the value of a column in mysql

How to modify the value of a column in mysql

青灯夜游
Release: 2022-04-14 15:26:54
Original
10174 people have browsed it

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;".

How to modify the value of a column in mysql

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 子句 ]
Copy after login

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;
Copy after login

How to modify the value of a column in mysql

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;
Copy after login

How to modify the value of a column in mysql

[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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template