当前位置:网站首页>数据库-视图详探
数据库-视图详探
2022-07-23 06:38:00 【kokotao】
一、定义视图:
1 视图的建立:SQL语言中用CREATE VIEW命令建立;
示例:
Create view <name> [<列名>[,<列名>]···)]
as <子查询> with check option];
子查询可以是任意select 语句
在关系数据库管理系统中 create view 语句的结果只是把视图的定义存入数据,并不会执行select语句。
二、行列子集视图
从单个基本表导出来的,并且只是去掉了基本表的某些行和某些列,但是保留了主码,则这类视图叫做行列自己视图。
create view IS_Student
as
selcet Sno,Sname,Sage
from student
where Sdept='IS';
IS_Student视图就可以看作是一个行列子集视图;
视图不仅可以建立在单个基本表上,也可建立在多个基本表上;
视图不仅可以建立在多个基本表上,还可以建立在一个或多个已定义好的视图上,或建立在基本表与视图上。
三、删除视图
语句:
drop view <视图名>[cascade];
四、查询视图
示例:在信息系学生中的视图找出年龄小于20岁的学生。
select Sno,Sage
from IS_Student
where Sage<20;
五 更新视图
更新视图一般用 insert(插入)、delete(删除)、update(修改)数据;
示例:
将计算机系学生视图IS_Student中学号为2011050321的学生姓名修改为“张宇”。
update IS_Student
set Sname='张宇'
where Sno='2011050321';
实际转换后的更新语句为:
update Student
set Sname='张宇'
where Sno='2011050321' and Sdept='IS';
六 视图的作用(优点)
1 视图能够简化用户的操作;
2 视图使用户能以多种角度看待同一数据;
3 视图对重构数据库提供一定程度的逻辑独立性;
4 视图能够对机密数据提供安全保护;
5 适当利用视图可以更清晰地表达查询;
边栏推荐
- 吴恩达机器学习系列篇p31~p42
- Debug No5 basic lighting
- Hardware system architecture of 4D millimeter wave radar
- 第七天笔记
- Beifu PLC and C transmit string array type variables through ads communication
- 倍福PLC和C#通过ADS通信传输int数组类型变量
- Beifu PLC and C transmit structure type variables through ads communication
- Point target simulation of SAR imaging (II) -- matlab simulation
- General contents of radar introduction column
- 射击 第 1-3 课:图像精灵
猜你喜欢
随机推荐
C language insert sort (direct insert sort)
Complex networks - common drawing software and libraries
Metaapp development interview questions
[jzof] 09 realize queue with two stacks
Introduction to radar part vii 1 radar and resolution
Shell运算符、$((运算式))” 或 “$[运算式]、expr方法、条件判断、test condition、[ condition ]、两个整数之间比较、按照文件权限进行判断、按照文件类型进行判断
【MUDUO】EPOLLPOLLER事件分发器
Opencv image processing (Part 1): geometric transformation + morphological operation
Charles抓包工具测试实战
[jzof] path in matrix 12
【cocos creator】spine动画,监听播放结束
Day 12 notes
基于BIM+3DGIS的智慧城市基础设施管理
Beifu PLC and C transmit string type through ads communication
Matplotlib- implement common probability distributions
太空射击 Part 2-3: 子弹与敌人碰撞处理
The unity model is displayed in front of the UI, and the UI behind it jitters
Introduction to JVM memory model
Opencv image processing (Part 2): edge detection + template matching + Hough transform
行业现状令人失望,工作之后我又回到UC伯克利读博了


![[jzof] 07 rebuild binary tree](/img/c8/5b67a3921afda5323b0d1eea6a78bc.png)






