Database--Basic Concepts and Functions of Views

From: Database--The Basic Concept and Function of Views

View (subquery): is a virtual table derived from one or more tables, the content of which is defined by the query. Has the structure of a normal table, but does not implement data storage.
Modification of views: Single-table views are generally used for query and modification, which will change the data of the basic table, and
multi-table views are generally used for querying and do not change the data of the basic table.

 

[sql] view plaincopy 
 
  1. --create view--  
  2. create or replace view v_student as select * from student;  
  3. --Retrieve data from view--  
  4. select * from v_student;  
  5. --delete view--  
  6. drop view v_student;  

 

effect:

①Simplifies the operation and defines frequently used data as views.

  When we use query, we need to use aggregate functions in many cases, and at the same time, we also need to display information of other fields, and may also need to associate with other tables. At this time, the statement written may be very long. If this action occurs frequently, We can create a view, after that, we only need to select * from view, which is very convenient. 

②Security, users can only query and modify the data they can see.

  Because the view is virtual and does not exist physically, it just stores the collection of data. We can provide the important field information in the base table to the user without passing the view. The view is a dynamic collection of data, and the data is accompanied by Updates to the base table. At the same time, the user cannot change or delete the view at will, which can ensure the security of the data. 

③ The logical independence shields the influence of the structure of the real table.

  Views allow some degree of independence between application and database tables. If there is no view, the application must be built on the table. With the view, the program can be built on the view, so that the program and the database table are separated by the view.

Disadvantages: 
① Poor performance
  The database must convert the view query into a query on the basic table. If the view is defined by a complex multi-table query, then even a simple query of the view, the database must turn it into a query Complicated combinations take a certain amount of time. 
②Restriction of modification
  When the user tries to modify some information of the view, the database must convert it into modification of some information of the basic table. For simple views, this is very convenient, but for more complex attempts , which may not be modifiable.

When defining database objects, views cannot be defined indiscriminately. The advantages and disadvantages of views should be weighed and the views should be defined reasonably.

View (subquery): is a virtual table derived from one or more tables, the content of which is defined by the query.

 

Has the structure of a normal table, but does not implement data storage.

Modification of views: Single table views are generally used for query and modification, which will change the data of the basic table.

   Multi-table views are generally used for queries and do not change the data of the underlying table.

 

[sql] view plaincopy 
 
  1. --create view--  
  2. create or replace view v_student as select * from student;  
  3. --Retrieve data from view--  
  4. select * from v_student;  
  5. --delete view--  
  6. drop view v_student;  

 

effect:

①Simplifies the operation and defines frequently used data as views.

②Security, users can only query and modify the data they can see.

③ The logical independence shields the influence of the structure of the real table.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325165225&siteId=291194637
Recommended