The role of database views

A view is a virtual table whose contents are defined by a query. Like a real table, a view contains a series of named columns and rows of data. However, views do not exist in the database as stored sets of data values. Row and column data comes from tables referenced by the query that defines the view, and is dynamically generated when the view is referenced. A view acts like a filter for the underlying tables referenced in it. A filter that defines a view can come from one or more tables in the current or other databases, or other views. A view is an SQL statement of a query stored in the database. It is mainly used for two reasons: for security reasons, views can hide some data, such as : The social insurance fund table, you can use the view to display only the name, address, but not the social security number and salary number, etc. Another reason is to make complex queries easy to understand and use. What the view does * Simplicity. What you see is what you need. Views not only simplify users' understanding of data, but also their actions. Those frequently used queries can be defined as views, so that the user does not have to specify all the conditions each time for subsequent operations. * safety. Through the view users can only query and modify the data they can see. Other data in the database is neither visible nor accessible. The database authorization command can make each user's retrieval in the database restricted to specific database objects , but cannot be authorized to specific rows and columns of the database. With views, users can be restricted to different subsets of data: Usage rights can be restricted to subsets of the base table's rows. Usage rights can be restricted to a subset of the columns of the base table. Usage rights can be restricted to a subset of the rows and columns of the base table. Usage rights can be restricted to rows defined by joins of multiple base tables. Usage rights can be restricted to statistical summaries of data in base tables. Usage rights can be restricted to a subset of another view, or a subset of views and base tables combined. * Logical data independence. Views help users shield the effects of changes to the real table structure

 

 

The advantages of using views in database development are:

    1. Can access a subset of the columns in the table. Some columns in the table are relatively sensitive data that users do not want to see, such as user passwords, employee salaries, etc. These columns can be hidden with views.

   2. Can access a subset of the rows in the table. Sometimes when users do not want to see data unrelated to TA, they can filter in the where condition. For example, employees of subsidiaries in the enterprise can only see the information of colleagues of the subsidiary where TA is located, and do not want the information of employees of other subsidiaries to be displayed. The view is composed of the filtered and queried dataset.

   3. Column names can be renamed. In the table, some column name definitions have no representative meaning, such as column "abc". In order to let users see the column name and know what data the column is, you can rename the column name when building the view.

   4. You can quickly access the data formed by the connection of two or more tables. Sometimes it is necessary to access the data set formed by the connection between the tables, and the queried data set can be defined as a view, which can help to quickly access the required data.  

   5. The data set returned by the aggregate function operation can be quickly read. Sometimes the user wants to read the result set after complex operations with aggregate functions, and each reading is very time-consuming. In this case, the data set after the operation can be formed into a view, which can avoid the need to perform operations every time. consume.

In general, using views increases security while speeding up queries.

 

Advantages and Disadvantages of Views

When designing programs, you must first understand the advantages and disadvantages of views, so that you can make use of your strengths and avoid weaknesses. Views have the following advantages:

● Simplicity. Views not only simplify users' understanding of data, but also their actions. Those frequently used queries can be defined as views, so that the user does not have to specify all the conditions each time for subsequent operations.

● Security. Through the view users can only query and modify the data they can see. Other data in the database is neither visible nor accessible. The database authorization command can make each user's retrieval in the database restricted to specific database objects, but cannot be authorized to specific rows and columns of the database. With views, users can be restricted to different subsets of data.

● Logical data independence. 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.

Views also have some disadvantages, the main ones are as follows.

● Performance: SQL Server must convert the query of the view into a query of the base table. If the view is defined by a complex multi-table query, then even a simple query of the view, SQL Server will turn it into a query Complicated combinations take a certain amount of time.

● Modification restrictions: When a user attempts to modify some rows of the view, SQL Server must convert it into modifications to some rows of the base table. This is convenient for simple views, but may not be modifiable for more complex views.

Therefore, when defining database objects, you cannot define views indiscriminately. You should weigh the advantages and disadvantages of views and define views reasonably.

Guess you like

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