Get the App
SLTechnology News&Howtos  ›  Database  › 

Detailed steps for MySQL to create a view

Shulou Source: shulou.com Published: 2022-06-01 18:45:37 10月04日 Update

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.

Tags: Views statements names steps data attributes algorithms structures selections text topics content places multiple mysteries fields that is text yes more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi vpn Shulou Information Xiaomi