SQL view role

The benefits of views can be mainly divided into four points:

The first point: Using views, you can customize user data and focus on specific data.

explain:

In the actual process, the company has staff with different roles. If we take the sales company as an example, the purchasing staff may need some data related to him, but the data that has nothing to do with him has no meaning to him. We can use this as an example. In fact, a view is specially created for the purchaser. When he queries data in the future, he only needs to select * from view_caigou.

 

The second point: using views, you can simplify data manipulation.

Explanation: When we use query, we need to use aggregate functions in many cases, and also display information of other fields, and may also need to associate with other tables, the statement written at this time may be very long, if this action occurs frequently If so, we can create the view, after that, we just need to select * from view1.

 

The third point: using views, the data in the base table has a certain degree of security.

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 fourth point: you can merge the separated data to create a partitioned view

With the development of society and the continuous expansion of the company's business volume, a large company has many subordinate companies. In order to facilitate management, we need to unify the structure of the table, regularly check the business situation of each company, and look at each company separately. The company's data is very inconvenient, and there is no good comparability. It would be much more convenient to combine these data into one table. At this time, we can use the union keyword to combine the data of each branch into one view.

 

Note: Views do not actually have any benefits in terms of execution efficiency. Each time a view is obtained, the database still needs to execute the statement to create the view.

 

CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326646816&siteId=291194637