当前位置:网站首页>数据库-视图详探
数据库-视图详探
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 适当利用视图可以更清晰地表达查询;
边栏推荐
- 【可视化调度软件】上海道宁为SMB组织带来NETRONIC下载、试用、教程
- Beifu and C transmit real type through ads communication
- Ti single chip millimeter wave radar code walk (XXV) -- angular dimension (3D) processing flow
- When using fastjson to parse and assign JSON data, the order of JSON fields is inconsistent
- MySQL的索引事务&&JDBC编程
- 4D antenna array layout design
- Google面试题原理解析 12个乒乓球其中有1个次品,用天平称重3次找出
- Debug No5 basic lighting
- Shooting games lesson 1-2: using sprites
- Jupyter notebook add existing virtual environment
猜你喜欢

轻重链剖分/树链剖分

Opencv image processing (Part 2): edge detection + template matching + Hough transform

Day 11 notes

Netease white hat hacker training camp notes (2)

Shooting lesson 1-01: Introduction

Functional testing to automated testing, sharing ten years of automated testing experience

com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value:

Charles' bag grabbing tool test practice

UI automation

Google面试题原理解析 12个乒乓球其中有1个次品,用天平称重3次找出
随机推荐
0722~ thread pool extension
知识图谱:基本概念
射击 第 1-01 课:入门
【cocos creator】spine动画,监听播放结束
[noi simulation race] I don't know which CF paper title it is (probability expectation, martingale's stop time theorem)
Matplotlib- implement common probability distributions
Successful joint commissioning of Vientiane Aoke and CoDeSys Technology
深入解读 EVM 的生态帝国
Power BI----综合应用
[jzof] path in matrix 12
What happens when you enter the web address and the web page is displayed
倍福PLC和C#通过ADS通信传输bool类型变量
Space shooting part 2-2: enemy spirit
Beifu PLC and C transmit bool array variables through ads communication
Why does the GOM engine version automatically drop the line or flash back?
吴恩达机器学习系列篇p31~p42
MetaApp开发面试题目
[daily training] 814. Binary tree pruning
【 Visual Dispatching Software】 Shanghai Dow Ning apporte netronic download, Trial, tutoriel pour l'Organisation SMB
PHP framework MVC class code audit