多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
**1. 查看一个数据库中有哪些视图** ```sql mysql> show tables; +-----------------------+ | Tables_in_learn_mysql | +-----------------------+ | author | | blog | | student | | v_author_blog | +-----------------------+ ``` **2. 查看视图字段信息** ```sql mysql> desc v_author_blog; +-------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+-------+ | id | int | NO | | 0 | | | author_name | varchar(255) | YES | | NULL | | | title | varchar(50) | YES | | NULL | | +-------------+--------------+------+-----+---------+-------+ ``` **3. 查看视图创建语句** ```sql mysql> show create view v_author_blog; CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_author_blog` AS select `a`.`id` AS `id`,`a`.`author_name` AS `author_name`,`b`.`title` AS `title` from (`author` `a` join `blog` `b`) where (`a`.`id` = `b`.`author_id`) order by `a`.`id` WITH CASCADED CHECK OPTION ``` **4. 查询视图** 视图创建后,就相当于一张表,对表的任何操作都可以用在视图上。 ```sql mysql> select * from v_author_blog where id != 1; +----+-------------+--------------+ | id | author_name | title | +----+-------------+--------------+ | 2 | 李四 | 李四博客 | | 3 | 王五 | 王五博客 | +----+-------------+--------------+ ```