Home > Database > Mysql Tutorial > body text

MySQL视图学习整理_MySQL

WBOY
Release: 2016-06-01 12:59:42
Original
1787 people have browsed it

第一部分:初级概念及应用

一,视图简介

MySQL的视图和Oracle视图是一个概念,就是一张虚拟表,没有任何数据的,数据还是存放在基表里面的;

二,添加视图
1:语法
CREATE
[OR REPLACE]
[ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
[DEFINER = { user | CURRENT_USER }]
[SQL SECURITY { DEFINER | INVOKER }]
VIEW view_name [(column_list)]
AS select_statement
[WITH [CASCADED | LOCAL] CHECK OPTION]
2:举例(创建视图 )
mysql> use ehrt;
Database changed
mysql> create algorithm = MERGE view t1 as select * from user;

三,修改视图
1:语法
ALTER
[ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
[DEFINER = { user | CURRENT_USER }]
[SQL SECURITY { DEFINER | INVOKER }]
VIEW view_name [(column_list)]
AS select_statement
[WITH [CASCADED | LOCAL] CHECK OPTION]
2:举例
mysql> alter view t1 as select * from user where name='Jacson';

四,查看视图

1.查看视图数据

mysql> use ehrt;
mysql> select * from t1;
+----+------+-----+
| id | name | sex |
+----+------+-----+
| 1 | Jacson | 0 |
| 2 | Bai | 0 |
+----+------+-----+

2 rows in set (0.00 sec)

2.查看视图结构

mysql> show create view t1G;

五,删除视图
mysql> drop view t1;

Query OK, 0 rows affected (0.00 sec)

第二部分:高级概念整理

一,视图的类型
mysql的视图有三种类型:MERGE、TEMPTABLE、UNDEFINED。如果不指定ALGORITHM子句,默认算法为UNDEFINED。这个方式决定了影响MySQL处理视图的速度。
1,MERGE,会将引用视图的语句的文本与视图定义合并起来,使得视图定义的某一部分取代语句的对应部分。
2,TEMPTABLE,视图的结果将被置于临时表中,然后使用它执行语句。
3,UNDEFINED,让自己MySQL选择所要使用的算法。

建议一般开发者,在物理主机内存不大或者考虑程序可移植的情况下一般选择MERGE

--未完待续

第三部分:高级应用

1.能否监控视图是否失效?

--未完待续

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template