A view is a virtual table derived from one or more tables. Essentially, a view is a stored query, and users can access the data defined by that view by querying the view itself. This chapter mainly introduces the basic concepts related to views. Views retrieve data from the underlying tables, which are referred to as base tables. The base tables can be actual tables or other views. All operations performed on a view actually access the base tables. Views can be used in many scenarios where tables are typically used.
Benefits
Views enable you to customize the presentation of data for different types of users. The following list describes the benefits of views:
- You can define frequently queried data as views to simplify operations. Database queries may use aggregate functions, display information of additional fields, and relate to other tables. As a result, the SQL statements can be rather complex. To avoid frequently executing these queries, you can create a view to simplify the query process. To obtain the desired query result after the view is created, execute the
SELECT * FROM view_namestatement. - You can only query and modify data displayed in the view. This improves data security. A view is a data set that is automatically updated based on changes in the base tables. As a virtual table, a view does not physically exist and displays only the result set of a query. Therefore, you can choose not to display sensitive fields of the base tables to users.
- A view is logically independent of the data structure of the base tables. Views allow applications to be independent of database tables. If views are not used, applications depend on real tables. After views are introduced, applications depend on views but not on real tables and are immune to changes in table schema.
Characteristics
Unlike tables, views do not occupy storage space or store data. A view is defined by a query that extracts or derives data from the referenced base tables. Therefore, a view requires no storage other than the storage for the query that defines the view in the data dictionary.