In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to create and use views in MySQL. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
1. What is a view?
View is a virtual table of MySQL. In the actual table, we can see the data of each row, while the view is another form of table. It can turn any query result into a virtual table and query it next time.
two。 Why use views?
1. Reusable
two。 Simplify complex SQL
3. Use the components of the table instead of the entire table
4. Protect data by granting users access to specific parts of the table instead of the entire table
3. How do I use the view?
For example, the following two tables, we can see that the relationship between the class table and the student table is 1-to-many, and the foreign key is on the student side.
If I want to inquire about all the students whose class is the Romance of the three Kingdoms, how should I inquire? Maybe you think of Left join or rigth join with inner connection Inner join or outer connection, and the query results are shown below.
As a result, it is obvious that the opinion is not wrong, Zhang Fei and Guan Yu have been inquired out. But you will find that the reusability of this writing is too poor, if I want to query the Shuihu transfer class, then I have to write such a long two-table join SQL, and the advantage of the view lies in this reusability, which allows users to write a lot less repetitive SQL. Next let's create the view and use the view to compare it.
As a result, we can see that after the view was created, we wrote a lot of code less, and the reusability is also very strong. In fact, the view is equivalent to giving the result of the query an alias, and this alias contains the result of the query. The next time we use it, we just use the alias directly, that is, the view.
4. Attention points for view updates
All attempts so far have been used with SELECT statements, and then can the view be updated? It depends on the situation.
Usually, the view is updatable (that is, you can INSERT,UPDATE and DELETE them), but updating the view will update the base table, because the view itself has no data.
On how to create and use views in MySQL to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.