网站开发设计比赛免费门户网站建设
文章目录
- 3.5 数据更新
 - 3.5.1 插入数据
 - 3.5.2 修改数据
 - 3.5.3 删除数据
 
- 3.6 空值的处理
 - 3.7 视图
 - 3.7.1 建立视图
 - 3.7.2 查询视图
 - 3.7.3 更新视图
 - 3.7.4 视图的作用
 
3.5 数据更新
3.5.1 插入数据
注意:插入数据时要满足表或者列的约束条件,否则插入失败,不成功!
// 挑选字段插入
insert into student(sno, sname) values('001','zs')
// 插入所有属性
insert into student values('001','zs','male')
// 一次插入多条
insert into student values('001','zs','male')
values('002','ls','famale')
// 插入子查询结果
insert into student2
select sno, sname
from student
 
3.5.2 修改数据
// 注意+where条件,否则全部被修改
update student
set sex = 'female'
where sno = '001'
//带子查询的修改
update student
set sex = 'male'
where sno in(select sno from scwhere sdept = 'cs')
 
- 练习



 
3.5.3 删除数据
// 注意加where条件,否则删除全部
delete from student where sno = '001'
// 带子查询的
delete from sc
where sno in(select snofrom studentwhere sdept = 'cs'
) 
3.6 空值的处理
- 空值的约束

 - 空值的运算

 - 练习

 
3.7 视图
3.7.1 建立视图
-  
创建视图


DBMS执行CREATE VIEW语句时只是把视图定义存入数据字典,并不执行其中的SELECT语句。在对视图查询时,按视图的定义从基本表中将数据查出。



 不指定属性列的坏处

 
- with check option



 
- 删除视图
 
- 格式


 
3.7.2 查询视图
- 视图消解


 
3.7.3 更新视图
- 视图消解,配合with check option



 - 不可更新的情况(无法消解)

 
3.7.4 视图的作用
- 视图能够简化用户的操作
 - 视图使用户能以多种角度看待同一数据
 - 视图对重构数据库提供了一定程度的逻辑独立性
 - 视图能够对机密数据提供安全保护
 - 适当的利用视图可以更清晰的表达查询
 
