首页 > 代码库 > 数据库(视图)

数据库(视图)

右键视图-新建视图

 

将想要建立关系的表选中并添加

选择所选表中需要的列的名称,关闭-添加名称-按确定即可完成

select *from score

select *from student

 

(select student.sno,sname,ssex,sbirthday,class,cno,DEGREE from student
join score on student.sno=score .sno)

--视图查询
select *from dfxx
select sname,ssex,sbirthday from dfxx
---代码创建视图---,只是表的连接作为一个新的表用
----视图实际就是对表的连接展示出来的结果建成虚拟表
----将连接语句存到数据库里,使用视图名替代连接语句
-----每次去查视图名时,实际是执行了表连接的代码查询
drop view dfxx--删除视图
create view studentscore
as
select student.sno,sname,ssex,sbirthday,class,cno,DEGREE from student
join score on student.sno=score .sno
go
select *from studentscore

--课程学生分数
select *from student

select *from course
select *from score

create view xuesheng
as
select student.sno,sname,ssex,sbirthday,class,score.cno,cname,tno, course.cname,tno from student,score,course
join score on student.sno=score .sno
join course on course.cno=score.Cno
go
select *from xuesheng
--修改等于删除重写

 

数据库(视图)