上接https://blog.csdn.net/qq_43473072/article/details/108484749
五、视图
- 视图:视图主要是查询时利用的工具,利用多表之间的联系创建一个临时的视图,同于存储多表中需要处理的有效数据。
- 创建:
create view (视图名字) as (多个子表的合成表)
mysql> create view author_room_view as select
r_id,room.a_id,a_name,r_name,r_type,r_popular
from room inner join author on room.a_id=author.a_id;
Query OK, 0 rows affected (0.02 sec)
- 查看:
select * from (视图名字)
mysql> select * from author_room_view;
+------+-------------+--------+-----------+--------+-----------+
| r_id | a_id | a_name | r_name | r_type | r_popular |
+------+-------------+--------+-----------+--------+-----------+
| 1 | 17645217970 | 阚建文 | HelloWord | NULL | 0 |
| 3 | 11111111111 | 小何壮 | 哈哈哈 | NULL | 0 |
| 4 | 12345678901 | 何世伟 | NewRoom | NULL | 0 |
| 5 | 13562895647 | 向日葵 | 阚建文 | NULL | 0 |
+------+-------------+--------+-----------+--------+-----------+
4 rows in set (0.00 sec)
3.删除:
drop view (视图名字)
mysql> drop view author_room_view;
Query OK, 0 rows affected (0.02 sec)
视图多和连接查询使用