如何创建没有任何列表的 MySQL 视图?
mysqlmysqli database
创建视图时,提供列表是可选的。以下示例将通过创建没有任何列表的视图来说明 −
mysql> Select * from student_detail; +-----------+-------------+------------+ | Studentid | StudentName | address | +-----------+-------------+------------+ | 100 | Gaurav | Delhi | | 101 | Raman | Shimla | | 103 | Rahul | Jaipur | | 104 | Ram | Chandigarh | | 105 | Mohan | Chandigarh | +-----------+-------------+------------+ 5 rows in set (0.17 sec) mysql> Create view View_student_detail AS SELECT * FROM Student_Detail; Query OK, 0 rows affected (0.17 sec)
正如我们在下面的查询中注意到的那样,在创建视图时我们没有给出任何列名,这就是为什么它是没有列表的视图。现在,如果我们使用视图的名称运行查询,那么我们将从创建视图的表中获取所有列。
mysql> Select * from View_student_detail; +-----------+-------------+------------+ | Studentid | StudentName | address | +-----------+-------------+------------+ | 100 | Gaurav | Delhi | | 101 | Raman | Shimla | | 103 | Rahul | Jaipur | | 104 | Ram | Chandigarh | | 105 | Mohan | Chandigarh | +-----------+-------------+------------+ 5 rows in set (0.00 sec)