SQL --更新语句

目录

1, 更新数据(update)

1-1, 使用过滤条件进行更新

1-2, 更新整列数据


1, 更新数据(update)

语法:update 表名 set 字段1='xxx', ..., 字段n='xxx' where 条件表达式;

1-1, 使用过滤条件进行更新

mysql> update dept set dname = 'fdsf', loc = 'fdsaf' where deptno >= 50 and deptno <= 70;
Query OK, 3 rows affected (0.17 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> select * from dept;
+--------+------------+----------+
| deptno | dname      | loc      |
+--------+------------+----------+
|     10 | ACCOUNTING | NEW YORK |
|     20 | RESEARCH   | DALLAS   |
|     30 | SALES      | CHICAGO  |
|     40 | OPERATIONS | BOSTON   |
|     50 | fdsf       | fdsaf    |
|     60 | fdsf       | fdsaf    |
|     70 | fdsf       | fdsaf    |
+--------+------------+----------+
7 rows in set (0.00 sec)

1-2, 更新整列数据

语法:update 表名 set 字段1='xxx', ..., 字段n='nnn';

mysql> update dept_copy set dname='aaa', loc='bbb';
Query OK, 7 rows affected (0.10 sec)
Rows matched: 8  Changed: 7  Warnings: 0

mysql> select * from dept_copy;
+--------+-------+------+
| deptno | dname | loc  |
+--------+-------+------+
|     10 | aaa   | bbb  |
|     20 | aaa   | bbb  |
|     30 | aaa   | bbb  |
|     40 | aaa   | bbb  |
|     50 | aaa   | bbb  |
|     60 | aaa   | bbb  |
|     70 | aaa   | bbb  |
|     80 | aaa   | bbb  |
+--------+-------+------+
8 rows in set (0.00 sec)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值