Overview
A standard view (hereinafter referred to as "view") in a database is a virtual table. It provides a logical representation of an SQL query result based on one or more actual tables (that is, base tables). Base tables can be tables or other views. A view does not store data, but stores a query for generating data. You can query the view to obtain the data defined by the view.
Benefits
Views have many benefits in database design and application:
Simplified queries
- 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.
Data security and isolation
- You can query and modify only visible data 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.
Logical independence
- 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 an actual data table, a view does not occupy storage space for storing data. A view has the following characteristics:
Storing only SQL queries
A view stores only the SQL query that defines the view, but not data.
Real-time data
A view is defined by an SQL query. Therefore, it always displays the latest data in its base tables.
No additionally occupied storage space
A view does not occupy storage space for storing data, except that its definition is stored in a data dictionary.
Tables can be replaced with views in most scenarios, especially in scenarios where custom, secure, and logically independent data display is required. Database administrators and developers can use views to efficiently manage database objects and provide necessary data access services for users.