How to create a view in mysql? (Pictures + Videos)

藏色散人
Release: 2018-10-25 15:19:35
Original
10565 people have browsed it

This article mainly introduces how to create a view in mysql.

First of all, everyone must knowWhat is a view?

A view refers to a view in a computer database, which is a virtual table whose content is defined by a query. So this statement may be relatively abstract for novices, but in our previous article, we have given you a detailed introduction to the basic knowledge of mysql data table view. Friends who need to know more can refer to the following article.

[What does mysql data table view mean? What are the uses?

The focus of this section is to explain to you how to create a view.

Below we will give you a detailed introduction to how to create a mysql data table view with a simple example.

The syntax for creating a view:

create view + 视图名 + as +select语句
Copy after login

1. Create a single table view

The syntax is as follows:

create view my_v1 as select * from stu;
Copy after login

How to create a view in mysql? (Pictures + Videos)

Here we create a view named my_v1 on the stu data table.

2. Create a multi-table view

The syntax is as follows:

create view my_v2 as select * from stu as left jion class c on s.c_id=c_id;
Copy after login

How to create a view in mysql? (Pictures + Videos)

Here we are Create a view named my_v2 on the two tables stu and class. And this view has four fields, including id (id in stu), name (name in stu), c_id (c_id in stu), title (title in class) fields.

Finally we can check whether the views are created successfully through the Navicat tool.

How to create a view in mysql? (Pictures + Videos)

As shown in the figure, both the single table view and the multi-table view were created successfully.

The data in the my_v2 view is as shown below.

How to create a view in mysql? (Pictures + Videos)

This article is an introduction to the method of creating single table and multi-table views in MySQL. It is also very simple. I hope it will be helpful to friends in need!

If you want to know more about mysql, you can follow the PHP Chinese website mysql video tutorial, everyone is welcome to refer to and learn!

The above is the detailed content of How to create a view in mysql? (Pictures + Videos). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template