update 修改记录字段值

update 更新/修改记录字段值

格式1:更新表内的所有记录
update 表名
set 字段1=字段1值,字段2=字段2值,字段N=字段N值;

格式2:只更新符合条件表内的部分记录
update 表名
set 字段1=字段1值,字段2=字段2值,字段N=字段N值
where 条件;

注意:
字段值要与字段类型相匹配
对于字符类型的字段,要用双引号引起来
若不使用where限定条件,会更新所有记录
限定条件时,只更新匹配条件的记录

mysql> select password,comment from user;
+----------+-----------------------------------------------------------------+
| password | comment |
+----------+-----------------------------------------------------------------+
| x | root |
| x | bin |
... ...

mysql> update user
-> set
-> password="A",comment="student";

mysql> select password,comment from user;
+----------+---------+
| password | comment |
+----------+---------+
| A | student |
| A | student |
... ...


mysql> select * from user where id=1;
+----+------+----------+------+------+---------+---------+-----------+
| id | name | password | uid | gid | comment | homedir | shell |
+----+------+----------+------+------+---------+---------+-----------+
| 1 | root | A | 0 | 0 | student | /root | /bin/bash |
+----+------+----------+------+------+---------+---------+-----------+


mysql> update user
-> set password="x",comment="root"
-> where id=1;


mysql> select * from user where id=1;
+----+------+----------+------+------+---------+---------+-----------+
| id | name | password | uid | gid | comment | homedir | shell |
+----+------+----------+------+------+---------+---------+-----------+
| 1 | root | x | 0 | 0 | root | /root | /bin/bash |
+----+------+----------+------+------+---------+---------+-----------+


mysql> select * from user where shell is null;
+----+------+----------+------+------+---------+---------+-------+
| id | name | password | uid | gid | comment | homedir | shell |
+----+------+----------+------+------+---------+---------+-------+
| 43 | tom | A | 4001 | 4002 | student | NULL | NULL |
+----+------+----------+------+------+---------+---------+-------+

 

转载于:https://www.cnblogs.com/summer2/p/10798303.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值