Introduction to Views in SQL Server _mssql

Source: Internet
Author: User

i): Definition of view

A view is a virtual table defined by a query based on one or more tables, which saves the specific definition of the query, and the view contains no data.

The view has no difference in operation from the datasheet, but the difference is in its nature. A datasheet is where the record is actually stored, whereas the view does not hold any records, it is actually a query statement.

The same data table, depending on the different needs of different users, you can create different views.

II): The role of the view

1): Filter the rows in the table
2): Prevent unauthorized users from accessing sensitive data
3): Reduce the complexity of the database
4): To abstract multiple physical data into a logical database

III): Create a View instance

Copy Code code as follows:

Create View view_officeinfo--(view name)
As (select A.name as property name, B.a_name as City, C.a_name as area, d.a_name as street from dbo. Office_info as A
INNER JOIN dbo. Base_area as B on a.cityid=b.a_id
INNER JOIN dbo. Base_area as C on a.areaid=c.a_id
INNER JOIN dbo. Base_area as D on a.streetid=d.a_id)--(SQL statement)

SELECT * from View_officeinfo (view name)

IV): Delete Modify View

Delete:

Copy Code code as follows:

if exists (SELECT * from sys.objects where name= ' View_officeinfo ')

Drop View_officeinfo

Modify:

Copy Code code as follows:

ALTER VIEW v_student as SQL statement

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.