Database--The basic concept and function of viewNovember 09, 2016 20:24:04Hits: 16506View (subquery): a virtual table that is exported from one or more tables whose contents are defined by the query. Has a structure of ordinary tables, but does not implement data storage.
Changes to Views: The single table view is typically used for querying and modifying, which alters the data of the base table,
Multi-table views are typically used for queries and do not alter the data of the underlying table.
[SQL]View PlainCopy
- --Create a view--
- Create or replace view v_student as select * from student;
- --Retrieving data from the view--
- SELECT * from v_student;
- --Delete View--
- Drop view v_student;
Role:
① simplifies operations by defining frequently used data as views.
When we use queries, we use aggregate functions in many cases, we also display information about other fields, and may also need to be associated to other tables, where the written statement can be very long, and if it happens frequently, we can create a view, and then we just need the SELECT * from View is OK, this is very convenient.
② security, users can only query and modify the data they can see.
Because the view is virtual, is not physically present, but the collection of data is stored, we can be the base table of important field information, can not pass the view to the user, the view is a dynamic collection of data, the data is updated with the base table updates. At the same time, the user view can not be arbitrarily changed and deleted, can guarantee the security of data.
③ The logic of independence, shielding the real table of the structure of the impact.
Views enable applications and database tables to be somewhat independent. If there is no view, the application must be built on the table. With a view, the program can be built on top of the view so that the program is separated from the database table by the view.
Disadvantages:
① Poor performance
The database must turn the view query into a query for the base table, and if the view is defined by a complex multi-table query, then even a simple query of the view, the database will have to be a complex combination, it takes some time.
② Modifying limits
When a user attempts to modify some information in a view, the database must turn it into a modification of some information about the base table, which is convenient for simple views, but may not be modifiable for more complex attempts.
When defining a database object, you cannot define the view without selecting it, you should weigh the advantages and disadvantages of the view and define the view reasonably.
View (subquery): a virtual table that is exported from one or more tables whose contents are defined by the query.
Has a structure of ordinary tables, but does not implement data storage.
Changes to Views: The single table view is typically used for querying and modifying, which alters the data of the base table,
Multi-table views are typically used for queries and do not alter the data of the underlying table.
[SQL]View PlainCopy
- --Create a view--
- Create or replace view v_student as select * from student;
- --Retrieving data from the view--
- SELECT * from v_student;
- --Delete View--
- Drop view v_student;
Role:
① simplifies operations by defining frequently used data as views.
② security, users can only query and modify the data they can see.
③ The logic of independence, shielding the real table of the structure of the impact.
Go to Database--basic concepts and roles of views