Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the functions of the mysql view

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you what the role of mysql view, I believe that most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Test table: user has id,name,age,sex field

Test table: goods has id,name,price field

Test table: ug has id,userid,goodsid field

Views are so powerful, here are some of the benefits I've experienced:

Function one:

Improved reusability, just like a function. If you want to get user's name and goods's name frequently. You should use the following sql language. Example:

Select a.name as username, b.name as goodsname from user as a, goods as b, ug as c where a.id=c.userid and c.goodsid=b.id

But it's not the same with views. Create a view other. Example

Create view other as select a.name as username, b.name as goodsname from user as a, goods as b, ug as c where a.id=c.userid and c.goodsid=b.id

Once the view is created, you can get the name of user and the name of goods in this way. Example:

Select * from other

With the above sql statement, you can get the name of user and the name of goods.

Function two:

Refactoring the database without affecting the operation of the program. If you need to demolish the user house table usera and table userb because of a certain requirement, the structure of the two tables is as follows:

Test table: usera has id,name,age field

Test table: userb has id,name,sex field

At this point, if the php side uses the SQL statement: select * from user;, it will indicate that the table does not exist, what to do in this case. Solution: create a view. The following sql statement creates a view:

Create view user as select a.name,a.age,b.sex from usera as a, userb as b where a.name=b.name

The above assumptions are that name is unique. At this point, the PHP side uses the SQL statement: select * from user; will not report anything wrong. This implements the function of changing the database structure without changing the script.

Function 3:

The security performance is improved. You can set different views for different users. For example, a user can only obtain name and age data of user table, but not sex data. You can create a view in this way. Examples are as follows:

Create view other as select a.name, a.age from user as a

In this case, using the SQL statement: select * from other; can only get name and age data at most, but not other data.

Function 4:

To make the data clearer. Create what kind of view you want. After the analysis of the above three functions, this effect should be easy to understand.

These are all the contents of the article "what are the functions of mysql views?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report