SQL Server View

Source: Internet
Author: User

View

1. What is a view?

A view is a virtual data table. The data records in the data table are obtained by a query statement.

 

2. Create a view Criterion

To create a view, consider the following guidelines:

# View names must follow the rules of identifiers. They must not be the same as the names of tables in the schema.

# You can create views for other views. Nested views are allowed, but no more than 32 layers can be nested. A view can have a maximum of 1024 fields.

# You cannot associate rules with default definitions in views.

# View query cannot contain the compute clause, compute by clause, or into keyword

# The query of the definition view cannot contain the order by clause, unless there is a top clause in the SELECT statement selection list

In the following cases, you must specify the name of each column in the View:

# How columns in a view are derived from arithmetic expressions, built-in functions, or constants

# Two or more columns in the view have the same name (usually because the view definition contains a join, two or more different columns have the same name)

# You want the column in the view to specify a name different from the original column (you can also rename the column in the view ). The View column inherits the Data Type of the original column no matter whether it is renamed or not.

 

3. Create a view

 
-- Create a view

 
If(Exists(Select*FromSYS. ObjectsWhereName ='V _ stu'))

 
Drop ViewV_stu

 
Go

 
Create ViewV_stu

As

 
SelectID, name, age, sexFromStudent;

4. Modify the view

 
Alter ViewV_stu

 
As

 
SelectID, name, sexFromStudent;

 
 

 
Alter ViewV_stu (No., name, gender)

As

 
SelectID, name, sexFromStudent

 
Go

 
Select*FromV_stu;

 
 

 
Select*FromInformation_schema.views;

Related Article

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.