MySQL 如何查看视图是由什么构成的
以下是语法 –
show create view yourViewName;
首先,让我们创建一张表 –
mysql> create table DemoTable
-> (
-> StudentName varchar(20)
-> );
Query OK, 0 rows affected (0.56 sec)
使用插入命令将一些记录插入表中 –
mysql> insert into DemoTable values('Chris');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values('Robert');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values('David');
Query OK, 1 row affected (0.13 sec)
使用select语句从表中显示所有记录 –
mysql> select *from DemoTable;
阅读更多:MySQL 教程
输出
这将产生以下输出 –
+-------------+
| StudentName |
+-------------+
| Chris |
| Robert |
| David |
+-------------+
3 rows in set (0.00 sec)
以下是为表创建视图的查询 –
mysql> CREATE VIEW view_DemoTable AS SELECT StudentName from DemoTable;
Query OK, 0 rows affected (0.12 sec)
以下是查看MySQL视图构成的查询 –
mysql> show create view view_DemoTable;
输出
这将产生以下输出 –
+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| View | Create View | character_set_client | collation_connection |
+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| view_DemoTable | CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL
SECURITY DEFINER VIEW `view_DemoTable` AS select `DemoTable`.`StudentName` AS
`StudentName` from `DemoTable` | utf8 | utf8_general_ci |
+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
1 row in set (0.00 sec)
让我们检查视图记录 –
mysql> select *from view_DemoTable;
输出
这将产生以下输出 –
+-------------+
| StudentName |
+-------------+
| Chris |
| Robert |
| David |
+-------------+
3 rows in set (0.05 sec)