SqlServer view presentations and create ways

1, a view description:

 (ps: school sqlServer view is learned after the interview asked, and could not answer too low, and then went to various search operations on the view also have their own understanding)
   actually view is a table, a single table or multiple tables after some data show that after the screening, the view is a predefined query select statements, for the simple
   view is that aspect is designed to let the viewing data, operate their view if not the original data table change so relatively safe, or else a database has many tables
   all to see will be very troublesome, view lets multiple tables make up a new table, this is the view, the view of the data can not add, delete, change operation.

1.1 Role of view of:

  1. Hidden from view the underlying table structure, simplifies data access operations, client no longer needs to know the relationship between structure and underlying tables.
  2. View provides a unified interface to access the data. (I.e., users may be allowed access to view the data security, without giving the user direct access to the underlying table)
  3. Thereby strengthening the security, so that users only see the data displayed view.
  4. May also be nested view, a view can be nested in another view.

2. Create view syntax:

2.1, the view to create, delete, view

 

Database view the situation:

 

2.2 of view to be modified:

3, inserting data into view

 In addition to recording the query view, the view may also be used to insert, update, delete a recording operation, to reduce the direct manipulation of the base table information to improve the data security.

 When you add data using the INSERT statement on the view, subject to the following rules.
  (1) When inserting the INSERT statement using the data table, the user must have the right to insert the data.
  (2) Since the view reference only part of the field in the table, you can explicitly specify values ​​referenced in the view field through the insert into view. The field in those tables not cited, will
           You know how the data should be filled in the absence of the specified value, so the view field unreferenced must have one of the following conditions.
           This field allows null values.
           This field has a default value.
           This field is the identifier field, an auto-fill according to the identification data and identification seeds increment.
           该字段的数据类型为timestamp或uniqueidentifier。
  (3)视图中不能包含多个字段值的组合,或者包含使用统计函数的结果。
  (4)视图中不能包含DISTINCT或GROUP BY子句。
  (5)如果视图中使用了WITH CHECK OPTION,那么该子句将检查插入的数据是否符合视图定义中SELECT语句所设置的条件。如果插入
           的数据不符合该条件,SQL Server会拒绝插入数据。
  (6)不能在一个语句中对多个基础表使用数据修改语句。因此,如果要向一个引用了多个数据表的视图添加数据时,必须使用多个INSERT
           语句进行添加。

 PS:

    • 视图不能包含 ORDER BY 子句,除非SELECT语句的选择列表中还有一个 TOP 子句。
    • 视图不能使用 INTO 关键字。视图不能包含 OPTION 子句。
    • 视图不能有对临时表或表变量的引用。视图最多可以有 1024 列。

Guess you like

Origin www.cnblogs.com/joeyJss/p/10950154.html