更新数据使用的是命令。
4.8.1 直接赋值更新
1. 语法
update 数据表
set 字段名1=新的赋值,字段名2=新的赋值,
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)where 条件
2. 实例
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)在执行以下语句。
――――――――――――――――――――――――――――――――――――― update scott.emp set empno=8888,ename='TOM',hiredate='03-9月 -2002 ' where empno=7566; ―――――――――――――――――――――――――――――――――――――
:第4章4.8481.sql。
单击按钮,出现如图4.49所示的结果。

4.8.2 嵌套更新
1. 语法
update 数据表
set 字段名1=(select 字段列表 from 数据表 where 条件),字段名2=(select 字段列表 from 数据表 where 条件),
2. 实例
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)在执行以下语句。
――――――――――――――――――――――――――――――――――――― update scott.emp set sal= ( select sal+300 from scott.emp where empno=7599 ) where empno=7599; ―――――――――――――――――――――――――――――――――――――
:第4章4.8482.sql。
单击按钮,出现如图4.50所示的结果。

以上我们学习了如何利用SQL对数据表中的数据进行录入、删除、更新和查询操作。读者利用这些实例可以结合自己的实际快速掌握这些基本的数据管理语句。


