CREATE VIEW NewMoon_employee AS
SELECT emp_id, fname, minit, lname,hire_date
FROM employee e, publishers p
WHERE e.pub_id = p.pub_id
AND pub_name = 'New Moon Books'
视图的创建:create view 视图名 as 查询语句
删除视图:drop view 视图名
创建视图的例子:
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
删除视图的例子:
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'view_stuInfo_stuMarks') /*检测是否存在*/
DROP VIEW view_stuInfo_stuMarks /*删除视图*/
GO