如何在不提供列列表的情况下创建 MySQL 视图?
在创建视图时,提供列列表是可选的。以下示例将演示如何创建不含任何列列表的视图:-
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)
广告