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

Detailed steps for MySQL to create a view

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

Share

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

Let's talk about the detailed steps of creating views in MySQL. The secret of the text is that it is relevant to the topic. So, instead of gossiping, let's go straight to the following, and I'm sure you'll benefit from reading this article on the detailed steps for creating views in MySQL.

1. View Overview: a view is a table derived from one or more tables, it is a virtual table, and the structure and data of the table depend on the base table

two。 Syntax format for creating views: view creation is based on SELECT statements

CREATE [OR REPLACE] [ALGORITHM] = {UNDEFINDE | MERGE | TEMPTABLE}]

VIEW view_name [(column_list)]

AS SELECT_statement

[WITH [CASCADED | LOCAL] CHECK OPTION]

/ / OR REPLACE indicates that the statement can replace the existing view

/ / ALGORITHM represents the algorithm for view selection

/ / UNDEFINDE represents MySQL automatic selection algorithm

/ / MERGE: merge the statement that uses the view with the view definition, and some part of the view definition replaces the corresponding part of the statement

/ / TEMPTABEL: view is stored in temporary table

/ / column_list: property list, which specifies the names of each property in the view

/ / AS: actions to be performed by the view

/ / CASCADED: cascading to meet the conditions of all related views and tables related to this view

/ / LOCAL: optional, as long as the definition of the view is satisfied

two。 Create a view on a single table

Create view play_v as select id,name from star

Select * from play_v

Create view play_v1 (number,player) as select id,name from star

3. Create a view on multiple tables

Create view pallet (number,player,team)

As

Select star.id,star.name,team.name from star,team where star.team_id = team.id

Select * from Putt

4. View view

DESCRIBE view name / / or DESC view name

Desc play_v1

SHOW TABLE STATUS LIKE 'View name'

Show table status like'poundt'

SHOW CREATE VIEW View name

Show create view play_v

5. Modify the view: when some fields in the basic table change

(1) use CREATE OR REPLACE VIEW statement to modify the view

Create or replace view play_v as select * from student

(2)

ALTER [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]

VIEW view_name [(column_list)]

AS SELECT_statement

[WITH [CASCADED | LOCAL] CHECK OPTION]

~ use alter to modify the view structure

Alter view play_v1 as select team_id,name from star

6. Update View

(1) UPDATE statement

Update view pairt set number = null

(2) INSERT statement

Insert into star values (11 Clay-Thompson, 4); the # view also changes.

(3) DELETE statement

The data deleted in the delete from view 11; # is the data in the basic table.

7. Delete View

DROP VIEW [IF EXISTS] view_name [, view_name.] [RESTRICT | CASCADE]

Drop view play_v1

Is there anything you don't understand about the detailed steps of creating a view in MySQL above? Or if you want to know more about it, you can continue to follow our industry information section.

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