Home > Database > Mysql Tutorial > How to create a view from a database table in MySQL?

How to create a view from a database table in MySQL?

黄舟
Release: 2017-08-07 15:44:56
Original
3627 people have browsed it

A view is a virtual table exported from one or more tables. It is a virtual table; it can facilitate users to operate data. How to create a view on an existing database table and view the created view? Information, the specific operations are as follows:

How to create a view from a database table in MySQL?


##1 .In order not to affect other database tables, create a new database table t_worker_info with the following code:

create table t_worker_info(
      id int(8) primary key not null auto_increment,
      w_id int(10) not null,
      w_name varchar(20) not null,
      w_age int(3),
      w_sex varchar(10),
      w_birth varchar(20)
   );
Copy after login

As shown in the figure below:

How to create a view from a database table in MySQL?

2. After creating t_worker_info, check the data structure. The code is as follows:

desc t_worker_info;
Copy after login

As shown in the figure below:

How to create a view from a database table in MySQL?

3. Double-click the selected database, right-click "Create View..." in Views, open the editing window, and enter the code in the window, the code is as follows:

CREATE VIEW `view_worker_info` AS
SELECT  * FROM t_worker_info;
Copy after login

As shown in the figure below:

How to create a view from a database table in MySQL?

How to create a view from a database table in MySQL?

4. View the basic information of creating a view, use desc or describe statement , the code is as follows:

desc view_worker_info;
Copy after login

As shown in the figure below:

How to create a view from a database table in MySQL?

##5. View view information, such as storage engine, data length, etc. , if the above indicators are all null, it means that the view is a virtual table, the code is as follows:

show table status like 'view_worker_info';
Copy after login
As shown in the figure below:

How to create a view from a database table in MySQL?## 6. To view the details of the created view, you need to use the show create view view name. The code is as follows:

show create view view_worker_info;
Copy after login
As shown in the figure below:

InstructionsHow to create a view from a database table in MySQL?

Note the difference between views and tables in MySQL

Learn how to create views

The above is the detailed content of How to create a view from a database table in MySQL?. 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