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 is the view in mysql?

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article is about what views refer to in mysql. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The view of mysql is an interface for storing data in mysql database, which can also be called a virtual table; these data can be data of one or more basic tables or views, or user-defined data; when the data in the basic table changes, the data in the view changes accordingly.

This article operating environment: Windows7 system, mysql5.0 version, Dell G3 computer.

Mysql View

View is an interface for storing data in mysql database

Introduction

A view is an interface for storing data, or a virtual table. This data can be data from one or more basic tables (or views). It can also be user-defined data. In fact, no data is stored in the view, but the data is still placed in the basic table. When the data in the basic table changes, the data in the view changes accordingly.

Action

1 view MySQL makes the query very clear, the data stored in the view is the data we want, and it can simplify the user's operation.

2 view MySQL makes the data more secure. The data in the view does not exist in the view or in the basic table. Through the view relationship, we can effectively protect our important data.

Types

There are three types of views for mysql: MERGE, TEMPTABLE, and UNDEFINED. If there is no ALGORITHM clause, the default algorithm is UNDEFINED (undefined). The algorithm affects how MySQL handles views.

1Magic merge merges the text of the statement referencing the view with the view definition so that some part of the view definition replaces the corresponding part of the statement.

The result of the view will be placed in the temporary table and then used to execute the statement.

3The MySQL will choose the algorithm to be used. If possible, it prefers MERGE over TEMPTABLE, because MERGE is usually more efficient, and if temporary tables are used, the view is not updatable.

Grammar

CREATE [OR REPLACE] [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}] VIEW view_name [(column_list)] AS select_ state [with [CASCADED | LOCAL] CHECK OPTION]

This statement creates a new view and replaces an existing view if an OR REPLACE clause is given. Select_statement is a SELECT statement that gives the definition of a view. This statement can be selected from a base table or other view.

This statement requires CREATE VIEW permissions for the view, as well as certain permissions on each column selected by the SELECT statement. You must have SELECT permission for columns that are used elsewhere in the SELECT statement. If you also have an OR REPLACE clause, you must have DROP permission on the view.

The view belongs to the database. By default, a new view is created in the current database. To explicitly create a view in a given database, you should specify the name db_name.view_name when you create it.

Mysql > CREATE VIEW test.v AS SELECT * FROM t

Tables and views share the same namespace in the database, so the database cannot contain tables and views with the same name.

The view must have a unique column name and must not be duplicated, just like the base table. By default, the column name retrieved by the SELECT statement is used as the view column name. To define a clear name for the view column, use the optional column_ list clause to list the ID separated by commas. The number of names in column_list must be equal to the number of columns retrieved by the SELECT statement.

The columns retrieved by the SELECT statement can be simple references to table columns. It can also be an expression that uses functions, constant values, operators, and so on.

Unqualified tables or views in the SELECT statement are interpreted according to the default database. By defining the table or view name with the appropriate database name, the view can refer to the view in the table or other database.

Thank you for reading! This is the end of this article on "what does View in mysql refer to?". I hope the above content can be of some help to you, so that 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.

Share To

Database

Wechat

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

12
Report