SQL view syntax and simple example

Source: Internet
Author: User

Syntax for creating views on SQL Server:

Create View

 

[< Database_name >.] [< Owner >.]

 

View_name [(column [,... n])]

 

[< View_attribute >[,... N]

 

As

 

Select_statement

[With check option]

 

< View_attribute >: =

 

{ENCRYPTION | SCHEMABINDING |

 

VIEW_METADATA}

Example 1: Create S_view1 that displays student ID, name, gender, and other information older than 20 years old

Create view S_view1

 

As

 

Select sno, sname, sex from s where age>20

Example 2: Create v_score1. The source of the basic table is S, C, SC. The selected fields are sno and sname in Table S, and the cname in Table C and score in Table SC; the data to be queried is the score of the students whose student number is 20030001.

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"

Execute the above program in the query analyzer to generate the view v_score1. To view data in the view, enter the following statement in the query Analyzer:

Select * from v_score1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.