View introduction in SQL Server
1): view definition
A view is a virtual table defined by a query based on one or more tables. It stores the specific definition of the query, and the view does not contain any data.
A view is essentially different from a data table in operations. A data table stores records. However, a view does not store any records, but stores query statements.
For the same data table, you can create different views based on different user needs.
Ii): Role of views
1): Filter rows in the table.
2): prevent unauthorized users from accessing sensitive data
3): reduce database complexity
4): Abstracts multiple physical data into a logical database.
3): Create a view instance
The Code is as follows:
Create view view_officeinfo -- (view name)
As (select A. Name as project Name, B. A _ Name as city, C. A _ Name as region, D. A _ Name as street from dbo. Office_Info as
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)
4): delete and modify a view.
Delete:
The Code is as follows:
If exists (select * from sys. objects where name = 'view _ officeinfo ')
Drop view_officeinfo
Modify:
The Code is as follows:
Alter view v_Student as SQL statement