我们如何创建带有列列表的 MySQL 视图?
短信预约 -IT技能 免费直播动态提醒
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 −
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)
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341