Mysql--information_scherma(虚拟库)

什么是视图

# 讲解:
      视图也可以理解为别名,创建视图关键字:create view as

# 视图基本操作
· 表格内容
mysql> select * from student;
+----+-----------+-----+--------+---------------------+
| id | name      | age | gender | cometime            |
+----+-----------+-----+--------+---------------------+
|  1 | 戴眼睛    |  23 | M      | 2020-07-15 06:59:15 |
|  2 | 王瘦子    |  28 | M      | 2020-07-15 06:59:49 |
|  3 | 王胖子    |  24 | M      | 2020-07-15 07:00:16 |
|  4 | 陈鱼落雁    |  21 | M      | 2020-07-15 07:00:38 |
|  5 | 高鸡窝    |  21 | M      | 2020-07-15 07:00:57 |
|  6 | 汤菜鱼    |  22 | F      | 2020-07-15 07:01:12 |
+----+-----------+-----+--------+---------------------+

## 简单查询,年龄大于21(此语句需要多次查询,所以后面用到了虚拟视图,方便后续查看)
mysql> select name age from student where age >21;
+-----------+
| age       |
+-----------+
| 戴眼睛     |
| 王瘦子    |
| 王胖子    |
| 汤菜鱼    |
+-----------+

## 创建虚拟视图
mysql> create view tcy as select name age from student where age >21;
Query OK, 0 rows affected (0.00 sec)

## 查看发现当前库下存在一个新的表,就是方才虚拟视图查看出来结果
mysql> select * from tcy;
+-----------+
| age       |
+-----------+
| 戴眼睛     |
| 王瘦子    |
| 王胖子    |
| 汤菜鱼    |
+-----------+
4 rows in set (0.00 sec)

后续再更新。。。。。

posted @ 2020-07-16 21:26  元气少女郭德纲!!  阅读(172)  评论(0编辑  收藏  举报