SQL Server創(chuàng)建視圖的語法
SQL Server創(chuàng)建視圖是很常見的操作,下面就為您介紹SQL Server創(chuàng)建視圖的語法,如果您在SQL Server創(chuàng)建視圖方面遇到過問題,不妨一看。
SQL Server創(chuàng)建視圖的語法:
- CREATE VIEW
- [ < database_name > .] [ < owner > .]
- view_name [ ( column [ ,...n ] ) ]
- [ WITH < view_attribute > [ ,...n ] ]
- AS
- select_statement
- [ WITH CHECK OPTION ]
- < view_attribute > ::=
- { ENCRYPTION | SCHEMABINDING |
- VIEW_METADATA }
例1:建立顯示年齡大于20歲的學(xué)生學(xué)號、姓名、性別等信息的S_view1
- create view S_view1
- as
- select sno,sname,sex from s where age>20
例2:創(chuàng)建v_score1,要求基本表來源:S,C,SC;選擇的字段為:S表中的sno、sname;C表中的cname及SC表中score;要求查詢的數(shù)據(jù)為學(xué)號為20030001的學(xué)生的考試成績。
- Use s
- create view v_score1
- As
- Select s.sno,s.sname,c.cname,sc.score
- From s,c,sc
- Where s.sno=sc.sno and c.cno=sc.cno and sno=“20030001”
在查詢分析器中執(zhí)行上面的程序,會生成視圖v_score1。為了查看視圖中的數(shù)據(jù),在查詢分析器中輸入語句:
- select * from v_score1。
【編輯推薦】