search
HomeDatabaseMysql TutorialHow to modify the content of a field in mysql

In mysql, you can use the UPDATE statement to modify the field content. This statement can update the contents of multiple fields. You only need to specify the field name and new field name to be modified after the keyword SET. Values ​​can be separated by commas "," between different fields. The syntax is "UPDATE table name SET field name 1 = new value 1 [, field name 2 = new value 2...] [WHERE clause]". The "WHERE clause" is used to specify modification conditions. If omitted, the contents of all rows under the specified field will be modified. If not omitted, the contents of the specified row can be modified.

How to modify the content of a field 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 field content.

MySQL UPDATE: Modify data (update data)

The UPDATE statement can modify and update the data (field content) of one or more tables.

The UPDATE statement can update the contents of one or more fields in the table. You only need to specify the field name and new value to be modified after the keyword SET. Different fields are separated by commas "," That’s it.

Syntax:

UPDATE 表名 SET 字段名1=新值1 [,字段名2=新值2…] [WHERE 子句 ]

The syntax 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 field values ​​in a row of data, each value in the SET clause can be separated by commas.

UPDATE statement example:

1. Modify the data in the table (omitting the WHERE clause)

In the tb_courses_new table, update the course_grade field value of all rows to 4.

mysql> UPDATE tb_courses_new SET course_grade=4;

Query OK, 3 rows affected (0.11 sec)
Rows matched: 4  Changed: 3  Warnings: 0

After updating, query the data to see if there is any change

mysql> SELECT * FROM tb_courses_new;

How to modify the content of a field in mysql

ok, you can see that all rows under the course_grade field are 4.

2. Modify the data in the table according to the conditions (do not omit the WHERE clause)

In the tb_courses table, update the record with course_id value 2 and change the course_grade field Change the value to 3.5 and change the course_name field value to "DB"

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

After updating, query the data to see if there is any change

mysql> SELECT * FROM tb_courses_new;

How to modify the content of a field in mysql

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

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
图文详解mysql架构原理图文详解mysql架构原理May 17, 2022 pm 05:54 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

mysql的msi与zip版本有什么区别mysql的msi与zip版本有什么区别May 16, 2022 pm 04:33 PM

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

mysql怎么去掉第一个字符mysql怎么去掉第一个字符May 19, 2022 am 10:21 AM

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

mysql怎么替换换行符mysql怎么替换换行符Apr 18, 2022 pm 03:14 PM

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql怎么将varchar转换为int类型mysql怎么将varchar转换为int类型May 12, 2022 pm 04:51 PM

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

MySQL复制技术之异步复制和半同步复制MySQL复制技术之异步复制和半同步复制Apr 25, 2022 pm 07:21 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

mysql怎么判断是否是数字类型mysql怎么判断是否是数字类型May 16, 2022 am 10:09 AM

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

带你把MySQL索引吃透了带你把MySQL索引吃透了Apr 22, 2022 am 11:48 AM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version