如何在MySQL中从视图创建表?
从下面的视图创建表是语法-
create table yourTableName select *from yourViewName;
让我们首先创建一个表-
mysql> create table DemoTable830(Name varchar(100));
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable830 values('Chris'); mysql> insert into DemoTable830 values('Robert'); mysql> insert into DemoTable830 values('David'); mysql> insert into DemoTable830 values('Mike');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable830;
这将产生以下输出-
+--------+ | Name | +--------+ | Chris | | Robert | | David | | Mike | +--------+ 4 rows in set (0.00 sec)
以下是创建视图的查询-
mysql> create view table_view AS select *from DemoTable830;
现在,我们将从视图中创建一个表。以下是查询-
mysql> create table DemoTable831 select *from table_view; Records: 4 Duplicates: 0 Warnings: 0
让我们检查从视图创建的表的记录-
mysql> select *from DemoTable831;
这将产生以下输出-
+--------+ | Name | +--------+ | Chris | | Robert | | David | | Mike | +--------+ 4 rows in set (0.00 sec)