27 修改数据:update
27 修改数据:update
语法格式:
update 表名 set 字段名1=值,字段名2=值2... where条件;
注意:没有条件整张表数据全部更新。
案例:将部门10的LOC修改为shanghai,将部门名称修改为renshibu。
update dept1 set loc = 'shanghai',dname='renshibu' where deptno = 10;
select * from dept1;
+--------+------------+----------+
| DEPTNO | DNAME | LOC |
+--------+------------+----------+
| 10 | renshibu | shanghai |
| 20 | RESEARCH | DALLAS |
| 30 | SALES | CHICAGO |
| 40 | OPERATIONS | BOSTON |
| 10 | renshibu | shanghai |
| 20 | RESEARCH | DALLAS |
| 30 | SALES | CHICAGO |
| 40 | OPERATIONS | BOSTON |
+--------+------------+----------+
更细所有记录
update dept1 set loc = 'x',dname = 'y';
select * from dept1;
+--------+-------+------+
| DEPTNO | DNAME | LOC |
+--------+-------+------+
| 10 | y | x |
| 20 | y | x |
| 30 | y | x |
| 40 | y | x |
| 10 | y | x |
| 20 | y | x |
| 30 | y | x |
| 40 | y | x |
+--------+-------+------+