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

How to use the mysql view

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

Share

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

This article mainly explains how to use mysql view, the content is clear and clear, interested friends can learn about it, I believe everyone will be helpful after reading.

What is a view: A view is a virtual table based on query results, and the table from which the data comes is called a base table. The creation and deletion of views does not affect base tables. Insert and modify views that affect base tables. If the view is from multiple base tables, the base tables cannot be modified. Views are based on query results, allowing views to hide data information from base tables that should not be shown to users (e.g., password information that a developer needs a user information table but should not show to his users). 2. A view is a virtual table that stores query information in the view for ease of operation.... Create a view: Grammar: create view name as select statement [with check option]; select statement can query results in multiple tables: joint query, join query] with check option will restrict insertion and modification operations according to conditional statements such as where (For example, the retrieved view data is male, and it is not allowed to change male to female) create view man_info as select * from student where gender="male"; supplement: view creation has another option: view algorithm View view: view is a virtual table, view statements for the table can be used to view all views: show tables/views; view structure: desc/describe/show columns from view name; view view creation statement: show create table/view view name; view modification: sometimes view definition errors may occur, so modify the view at this time. Grammar: alter view view name as new select statement;create view user_view as select * from user;alter view user_view as select username,money from user; supplement: since the view is a virtual table, there is also a way to modify the view: create or replace view creation statement;[will overwrite the old view with the new view] view deletion: syntax: drop view view name [, view name…]; example: drop view student_class,student_info; Data manipulation for views: If the view is from multiple base tables, the base tables cannot be modified. In theory, however, updates are allowed. View data viewing: syntax: select field list from view name;[same as basic table query operation] Data Insert for View: Cannot insert data from multiple base tables. Syntax:insert into view-name values();[insert operation is consistent with basic table.] Note: The view structure is derived from the base table, so it is subject to the constraints of the base table. If a field is not allowed to be empty, but the view insert operation does not assign a value, the insert will fail. View data modification: syntax: update view name set field name = value where condition;[consistent with modification operation of basic table] Deletion of view data: Cannot delete data from multiple base tables. Syntax: delete from view name where condition;[consistent with deletion operation of basic table.] After reading the above content, is there a further understanding of how to use mysql view, if you want to learn more, welcome to pay attention to 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