创建视图:

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>