视图
2016-04-28 13:19
232 查看
创建视图:
mysql> create or replace view test_view as select a.ename,a.sal,b.deptname from test2 as a ,test1 as b where a.deptno=b.deptno;
Query OK, 0 rows affected (0.04 sec)
mysql>
查看视图:
mysql> show tables;
mysql> select * from test_view;
+--------+---------+----------+
| ename | sal | deptname |
+--------+---------+----------+
| zzx | 2000.00 | tech |
| lisa | 4000.00 | tech |
| bjguan | 5000.00 | hr |
| zzx | 2000.00 | tech |
+--------+---------+----------+
4 rows in set (0.00 sec)
mysql>
mysql> show table status like "test_view"\G
mysql> show create view test_view \G
*************************** 1. row ***************************
View: test_view
Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `test_view` AS select `a`.`ename` AS `ename`,`a`.`sal` AS `sal`,`b`.`deptname` AS `deptname` from (`test2` `a` join `test1` `b`) where (`a`.`deptno` = `b`.`deptno`)
character_set_client: utf8mb4
collation_connection: utf8mb4_general_ci
1 row in set (0.00 sec)
mysql>
mysql> select * from information_schema.views where table_name="test_view"\G
*************************** 1. row ***************************
TABLE_CATALOG: def
TABLE_SCHEMA: wqh
TABLE_NAME: test_view
VIEW_DEFINITION: select `a`.`ename` AS `ename`,`a`.`sal` AS `sal`,`b`.`deptname` AS `deptname` from `wqh`.`test2` `a` join `wqh`.`test1` `b` where (`a`.`deptno` = `b`.`deptno`)
CHECK_OPTION: NONE
IS_UPDATABLE: YES
DEFINER: root@localhost
SECURITY_TYPE: DEFINER
CHARACTER_SET_CLIENT: utf8mb4
COLLATION_CONNECTION: utf8mb4_general_ci
1 row in set (0.00 sec)
mysql>
删除视图:
mysql> drop view test_view;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> create or replace view test_view as select a.ename,a.sal,b.deptname from test2 as a ,test1 as b where a.deptno=b.deptno;
Query OK, 0 rows affected (0.04 sec)
mysql>
查看视图:
mysql> show tables;
mysql> select * from test_view;
+--------+---------+----------+
| ename | sal | deptname |
+--------+---------+----------+
| zzx | 2000.00 | tech |
| lisa | 4000.00 | tech |
| bjguan | 5000.00 | hr |
| zzx | 2000.00 | tech |
+--------+---------+----------+
4 rows in set (0.00 sec)
mysql>
mysql> show table status like "test_view"\G
mysql> show create view test_view \G
*************************** 1. row ***************************
View: test_view
Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `test_view` AS select `a`.`ename` AS `ename`,`a`.`sal` AS `sal`,`b`.`deptname` AS `deptname` from (`test2` `a` join `test1` `b`) where (`a`.`deptno` = `b`.`deptno`)
character_set_client: utf8mb4
collation_connection: utf8mb4_general_ci
1 row in set (0.00 sec)
mysql>
mysql> select * from information_schema.views where table_name="test_view"\G
*************************** 1. row ***************************
TABLE_CATALOG: def
TABLE_SCHEMA: wqh
TABLE_NAME: test_view
VIEW_DEFINITION: select `a`.`ename` AS `ename`,`a`.`sal` AS `sal`,`b`.`deptname` AS `deptname` from `wqh`.`test2` `a` join `wqh`.`test1` `b` where (`a`.`deptno` = `b`.`deptno`)
CHECK_OPTION: NONE
IS_UPDATABLE: YES
DEFINER: root@localhost
SECURITY_TYPE: DEFINER
CHARACTER_SET_CLIENT: utf8mb4
COLLATION_CONNECTION: utf8mb4_general_ci
1 row in set (0.00 sec)
mysql>
删除视图:
mysql> drop view test_view;
Query OK, 0 rows affected (0.00 sec)
mysql>
相关文章推荐
- 动态生成SQL Server视图作业
- 关于Ruby on Rails视图编写的一些建议
- SQL server 视图(view)介绍
- dba_indexes视图的性能分析
- 简析SQL Server数据库用视图来处理复杂的数据查询关系
- SQL SERVER先判断视图是否存在然后再创建视图的语句
- sql server判断数据库、表、列、视图是否存在
- MySQL入门教程(七)之视图
- ASP.NET Web API教程 创建Admin视图详细介绍
- ASP.NET MVC4入门教程(六):验证编辑方法和编辑视图
- Oracle Scott创建视图权限不足解决办法
- SQLite教程(三):数据表和视图简介
- oracle中的视图详解
- MVC Ajax Helper或Jquery异步加载部分视图
- Android网格视图GridView的使用
- 简介AngularJS的视图功能应用
- Zend Framework教程之视图组件Zend_View用法详解
- ASP.NET MVC中的视图生成实例分析
- 跟我学Laravel之视图 & Response
- Laravel 5框架学习之向视图传送数据