set field 1 = value where ". When multiple values ​​need to be modified, each value in the set clause can be separated by commas."/> set field 1 = value where ". When multiple values ​​need to be modified, each value in the set clause can be separated by commas.">

Home  >  Article  >  Database  >  sql statement to modify data

sql statement to modify data

angryTom
angryTomOriginal
2020-02-06 11:02:2433141browse

sql statement to modify data

sql statement to modify data

In SQL, you can use the UPDATE statement to modify and update the data of one or more tables.

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.

Example:

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)

PHP Chinese website has a large number of free SQL tutorials, everyone is welcome to learn!

The above is the detailed content of sql statement to modify data. 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
Previous article:SQL fuzzy query statementNext article:SQL fuzzy query statement