
As we know that while creating a view, providing the list of columns is optional. But if we are providing the name of the columns while creating the view then the number of names in the list of columns must be the same as the number of columns retrieved by the SELECT statement.
Example
The following example will illustrate by creating the views with column list −
医院诊所网站源码小兵系统基于PHP+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_columns AS SELECT Studentid, StudentName FROM Student_Detail; Query OK, 0 rows affected (0.10 sec)
在上面的代码中,我们给出了两列,并在运行查询以从视图中获取数据后,它将仅显示我们在创建视图时给定的列名。
mysql> Select * from View_Student_detail_columns; +-----------+-------------+ | Studentid | StudentName | +-----------+-------------+ | 100 | Gaurav | | 101 | Raman | | 103 | Rahul | | 104 | Ram | | 105 | Mohan | +-----------+-------------+ 5 rows in set (0.08 sec)









