How to modify a row of data in the data table in mysql: use the UPDATE statement, the syntax format "UPDATE
SET field 1=value 1 [, field 2=value 2...] [WHERE clause ] [ORDER BY clause] [LIMIT clause]".
(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 子句]Copy after loginThe syntax description is as follows:
: 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='DB',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)Copy after loginNote: 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!
Related labels:source:php.cnPrevious article:How to set foreign key constraints in mysql? Next article:How to allow mysql to be accessed from the external networkStatement of this WebsiteThe 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.cnLatest Articles by Author
2023-04-26 17:59:18 2023-04-26 17:47:48 2023-04-26 17:41:42 2023-04-26 17:37:05 2023-04-26 17:31:25 2023-04-26 17:27:32 2023-04-25 19:57:58 2023-04-25 19:53:11 2023-04-25 19:49:11 2023-04-25 19:41:54Latest IssuesHow to group and count in MySQL? I'm trying to write a query that extracts the total number of undeleted messages sent to f...From 2024-04-06 18:30:1701353MySQL gets data from multiple tables I have a eg_design table which contains the following columns: and eg_domains table which ...From 2024-04-06 18:42:4402479Related TopicsMore>