SET field 1=value 1 [, field 2=value 2...] [WHERE clause] [ORDER BY clause] [ LIMIT clause]"."/> SET field 1=value 1 [, field 2=value 2...] [WHERE clause] [ORDER BY clause] [ LIMIT clause]".">

Home >Database >Mysql Tutorial >How to modify a row of data in mysql data table?

How to modify a row of data in mysql data table?

青灯夜游
青灯夜游Original
2020-10-12 12:51:4717315browse

How to modify a row of data in the data table in mysql: use the UPDATE statement, the syntax format "UPDATE ccc43248daffbac9770dee47fdaff697 SET field 1=value 1 [, field 2=value 2...] [WHERE clause ] [ORDER BY clause] [LIMIT clause]".

How to modify a row of data in mysql data table?

(Recommended tutorial: mysql video tutorial)

In MySQL, you can use the UPDATE statement to Modify and update data in one or more tables.

Basic syntax of the UPDATE statement

Use the UPDATE statement to modify a single table. The syntax format is:

UPDATE <表名> SET 字段 1=值 1 [,字段 2=值 2… ] [WHERE 子句 ]
[ORDER BY 子句] [LIMIT 子句]

The syntax description is as follows:

  • 722e3d59fd24604761db25f00f9b264f: used to specify the name of the table to be updated.

  • SET clause: used to specify the column name and its 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.

  • ORDER BY clause: Optional. Used to limit the order in which rows in a table are modified.

  • LIMIT clause: Optional. Used to limit the number of rows that are modified.

Note: When modifying multiple column values ​​in a row of data, each value in the SET clause can be separated by commas.

Modify the data in the table based on conditions

Example: In the tb_courses table, update the record with course_id value 2 and change the course_grade field value to 3.5 , change the course_name field value to "DB", and enter the SQL statement and execution results as shown below.

mysql> UPDATE tb_courses_new
    -> SET course_name=&#39;DB&#39;,course_grade=3.5
    -> WHERE course_id=2;
Query OK, 1 row affected (0.13 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> SELECT * FROM tb_courses_new;
+-----------+-------------+--------------+------------------+
| course_id | course_name | course_grade | course_info      |
+-----------+-------------+--------------+------------------+
|         1 | Network     |            4 | Computer Network |
|         2 | DB          |          3.5 | MySQL            |
|         3 | Java        |            4 | Java EE          |
|         4 | System      |            4 | Operating System |
+-----------+-------------+--------------+------------------+
4 rows in set (0.00 sec)

Note: Ensure that UPDATE ends with a WHERE clause. The WHERE clause specifies the conditions that the updated records need to meet. If the WHERE clause is ignored, MySQL will update all rows in the table.

The above is the detailed content of How to modify a row of data in mysql data table?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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