SQL SERVER 创建视图

CREATE VIEW view_name 
   AS
    <select语句>
IF EXISTS (SELECT * FROM sysobjects WHERE /*检测是否存在*/
                         name = 'view_stuInfo_stuMarks')
     DROP VIEW view_stuInfo_stuMarks /*删除视图*/
GO
CREATE VIEW view_stuInfo_stuMarks /*创建视图*/
  AS
    SELECT 姓名=stuName,学号=stuInfo.stuNo,
      笔试成绩 =writtenExam,  机试成绩=labExam,
            平均分=(writtenExam+labExam)/2
               FROM stuInfo LEFT JOIN stuMarks
                     ON stuInfo.stuNo=stuMarks.stuNo
GO
SELECT * FROM view_stuInfo_stuMarks /*使用视图*/

posted on 2014-02-10 17:16  明天521  阅读(225)  评论(0编辑  收藏  举报