標籤:sql 資料集 使用者 tab 名稱 str alt create table
視圖是一個虛擬表(非真實存在),其本質是【根據SQL語句擷取動態資料集,並為其命名】,使用者使用時只需使用【名稱】即可擷取結果集,並可以將其當作表來使用
一:建立視圖
create view viewname as select tname from table1,table2 where condition
MariaDB [test2]> create view student2 as select * from student;Query OK, 0 rows affected (0.02 sec)MariaDB [test2]> show tables;+-----------------+| Tables_in_test2 |+-----------------+| a || b || student || student2 |+-----------------+4 rows in set (0.00 sec)
二:刪除視圖
drop view viewname
MariaDB [test2]> drop view student2;Query OK, 0 rows affected (0.00 sec)MariaDB [test2]> show tables;+-----------------+| Tables_in_test2 |+-----------------+| a || b || student |+-----------------+3 rows in set (0.00 sec)
三:修改視圖
alter view viewname as select tname from table1,table2 where condition
MariaDB [test2]> alter view student2 as select * from a;Query OK, 0 rows affected (0.00 sec)
資料庫-mysql視圖