MySQL view is a virtual table whose contents are defined by a query; the view contains a series of named column and row data, and the row and column data comes from the table referenced by the query that customizes the view, and in the reference view Dynamically generated, simply put, the view is a table composed of select results.
##The operating environment of this tutorial: Windows 10 system, MySQL5.7 version, Dell G3 computer. What is a MySQL view? View meaning and usage analysis
What is a view
A view is a virtual table whose content is defined by a query.
Like a real table, a view contains a series of named column and row data.
Row and column data come from the table referenced by the custom view's query and are dynamically generated when the view is referenced.
Simply speaking, a view is a table composed of select results.
As an exampleUse the query table command
SELECT * FROM 表名 ;
Copy after login
If you find out, you can see a table, and what you see is called a view.
Characteristics of views
A view is a reference to several basic tables, a virtual table, and a query statement execution the result of.
It does not store specific data (if the basic table data changes, the view will also change accordingly).
It can perform addition, deletion, modification and query operations just like the basic table (the addition, deletion and modification operations are subject to conditional restrictions).
The role of the view
Improve security: Create a view and define the data operated by the view. Then bind the user permissions to the view. This method uses a feature: the grant statement can grant permissions to the view.
For example: the data queried by the administrator contains the password of each user, and the administrator does not want the user to see the password, he can create a view so that only the user can see the administrator. I want him to see the data
to improve query performance.
Improves the independence of data.
Create a view
Suppose we have a student table as follows
Requirements: Create a view and query students older than 20
CREATE VIEW stu_age_view
AS(SELECT * FROM stu WHERE age>20);
Copy after login
Click the view to open and you can see the table you just created
The content in the table is the requirement content Based on the view, we can continue to query the desired content, such as querying people named ls who are over 21 years old. View-based query can improve efficiency and reduce operating costs.
Modify view
CREATE OR REPLACE VIEW 视图名 AS(SELECT [...] FROM [...] );
Copy after login
For example: the view "stu_age_view" created above is for students over 20 years old, now it is modified to all students .
CREATE OR REPLACE VIEW stu_age_view
AS(SELECT * FROM stu );
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn