目录
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)