公司高端网站建,搜索引擎优化的重要性,免费网站建站排行榜,国外超酷设计网站MySQL从小白到总裁完整教程目录:https://blog.csdn.net/weixin_67859959/article/details/129334507?spm1001.2014.3001.5502
语法:
update 表名 列名该列新值, 列名该列新值, ... where 记录匹配条件; 说明#xff1a;update 更新、修改 set 设置 …MySQL从小白到总裁完整教程目录:https://blog.csdn.net/weixin_67859959/article/details/129334507?spm1001.2014.3001.5502
语法:
update 表名 列名该列新值, 列名该列新值, ... where 记录匹配条件; 说明update 更新、修改 set 设置 如果不写where条件表示对所有行都操作 比如: 案例更新test03表针对日期(etime)是2022-06-01的记录将姓名(name)改为mary update test03 set nameMary where etime2022-06-01; 结果:
mysql select * from test03;
-----------------------------------------
| name | age | salary | etime | address |
-----------------------------------------
| king | 20 | 999.00 | NULL | NULL |
| tom | 23 | NULL | 2022-06-30 | NULL |
| rose | NULL | NULL | NULL | 北京 |
| NULL | 19 | 777.00 | 2022-06-01 | NULL |
| lucy | 21 | 88.00 | NULL | 上海 |
-----------------------------------------
5 rows in set (0.05 sec)mysql update test03 set nameMary where etime2022-06-01;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql select * from test03;
-----------------------------------------
| name | age | salary | etime | address |
-----------------------------------------
| king | 20 | 999.00 | NULL | NULL |
| tom | 23 | NULL | 2022-06-30 | NULL |
| rose | NULL | NULL | NULL | 北京 |
| Mary | 19 | 777.00 | 2022-06-01 | NULL |
| lucy | 21 | 88.00 | NULL | 上海 |
-----------------------------------------
5 rows in set (0.00 sec)练习更新test03表针对姓名(name)是rose的记录将年龄(age)改为108岁 mysql select * from test03;
-----------------------------------------
| name | age | salary | etime | address |
-----------------------------------------
| king | 20 | 999.00 | NULL | NULL |
| tom | 23 | NULL | 2022-06-30 | NULL |
| rose | NULL | NULL | NULL | 北京 |
| Mary | 19 | 777.00 | 2022-06-01 | NULL |
| lucy | 21 | 88.00 | NULL | 上海 |
-----------------------------------------
5 rows in set (0.00 sec)mysql update test03 set age108 where namerose;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql select * from test03;
-----------------------------------------
| name | age | salary | etime | address |
-----------------------------------------
| king | 20 | 999.00 | NULL | NULL |
| tom | 23 | NULL | 2022-06-30 | NULL |
| rose | 108 | NULL | NULL | 北京 |
| Mary | 19 | 777.00 | 2022-06-01 | NULL |
| lucy | 21 | 88.00 | NULL | 上海 |
-----------------------------------------
5 rows in set (0.00 sec) 练习更新test03表针对日期(etime)是2022-06-30的记录将工资(salary)修改为999地址(address)变更为广州 mysql select * from test03;
-----------------------------------------
| name | age | salary | etime | address |
-----------------------------------------
| king | 20 | 999.00 | NULL | NULL |
| tom | 23 | NULL | 2022-06-30 | NULL |
| rose | 108 | NULL | NULL | 北京 |
| Mary | 19 | 777.00 | 2022-06-01 | NULL |
| lucy | 21 | 88.00 | NULL | 上海 |
-----------------------------------------
5 rows in set (0.00 sec)mysql update test03 set salary999, address广州- where etime2022-06-30;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql
mysql #查询验证
mysql select * from test03;
-----------------------------------------
| name | age | salary | etime | address |
-----------------------------------------
| king | 20 | 999.00 | NULL | NULL |
| tom | 23 | 999.00 | 2022-06-30 | 广州 |
| rose | 108 | NULL | NULL | 北京 |
| Mary | 19 | 777.00 | 2022-06-01 | NULL |
| lucy | 21 | 88.00 | NULL | 上海 |
-----------------------------------------
5 rows in set (0.00 sec) 案例针对test03表将所有记录的日期(etime)都改为2022-01-01 分析:更新语句中不写where子句表示对所有的行的指定列进行修改
mysql update test03 set etime2022-01-01;
Query OK, 5 rows affected (0.03 sec)
Rows matched: 5 Changed: 5 Warnings: 0mysql select * from test03;
-----------------------------------------
| name | age | salary | etime | address |
-----------------------------------------
| king | 20 | 999.00 | 2022-01-01 | NULL |
| tom | 23 | 999.00 | 2022-01-01 | 广州 |
| rose | 108 | NULL | 2022-01-01 | 北京 |
| Mary | 19 | 777.00 | 2022-01-01 | NULL |
| lucy | 21 | 88.00 | 2022-01-01 | 上海 |
-----------------------------------------
5 rows in set (0.00 sec) 练习针对test03表将地址(address)为北京的记录工资(salary)改为666 mysql update test03 set salary666 where address北京;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql select * from test03;
-----------------------------------------
| name | age | salary | etime | address |
-----------------------------------------
| king | 20 | 999.00 | 2022-01-01 | NULL |
| tom | 23 | 999.00 | 2022-01-01 | 广州 |
| rose | 108 | 666.00 | 2022-01-01 | 北京 |
| Mary | 19 | 777.00 | 2022-01-01 | NULL |
| lucy | 21 | 88.00 | 2022-01-01 | 上海 |
-----------------------------------------
5 rows in set (0.00 sec)