zoukankan      html  css  js  c++  java
  • 20141110--SQL视图

    --------------------------视图---------------------
    --视图是一个虚拟表,数据来自于原表,原表的数据改变,视图也会改变
    select Student.Sno,sname,ssex,class,cno,degree from Student join Score on Student.Sno=Score.Sno 
    --以下代码由系统自己生成,在左边的对象管理器中,右键视图-新建视图
    SELECT     dbo.Student.Sno AS Expr2, dbo.Student.Sname AS Expr3, dbo.Student.Ssex AS Expr4, dbo.Student.Sbirthday AS Expr5, dbo.Student.Class AS Expr6, dbo.Score.Cno AS Expr7, 
                          dbo.Score.Degree AS Expr8
    FROM         dbo.Student INNER JOIN
                          dbo.Score ON dbo.Student.Sno = dbo.Score.Sno
    ----------------------------------------
    --用代码生成视图
    --只能有表连接 join on, 不能出现聚合函数,等等
    create view St_Sc
    as
    select Student.Sno,sname,ssex,class,cno,degree from Student join Score on Student.Sno=Score.Sno 
    ----------查询视图
    select *from St_Sc
    -----------------------不用 join on
    create view ssc
    as
    select Student.Sno,Sname,Ssex,Sbirthday,Class,Score.Cno,Cname,Tno,Degree  
    from Student,Course,Score where Student.Sno=Score.Sno and Score.Cno=Course.Cno
    ------------------使用 join on
    create view sss
    as
    select Student.Sno,Sname,Ssex,Sbirthday,Class,Score.Cno,Cname,Tno,Degree from Score 
    join Course on Score.Cno=Course.Cno
    join Student on Student.Sno=Score.Sno
    
    select *from ssc
    select *from sss
    ------------修改视图
    ----需要重写,相当于删掉重建
    alter view sss
    as
    select Student.Sno,Sname,Ssex,Class,Score.Cno,Cname,Tno,Degree from Score 
    join Course on Score.Cno=Course.Cno
    join Student on Student.Sno=Score.Sno

    查询视图结果:

  • 相关阅读:
    什么是垃圾回收
    Oracle GoldenGate学习之Goldengate介绍
    JVM虚拟机选项:Xms Xmx PermSize MaxPermSize区别
    查看linux系统版本命令
    Case when 的用法,简单Case函数
    case when then else end
    ORACLE视图添加备注
    修改 tomcat 内存
    Linux 内存机制详解宝典
    oracle正则表达式regexp_like的用法详解
  • 原文地址:https://www.cnblogs.com/Tirisfal/p/4087286.html
Copyright © 2011-2022 走看看