
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 −
Zyro AI Background Remover
Zyro推出的AI图片背景移除工具
55 查看详情
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)
以上就是我们如何创建带有列列表的 MySQL 视图?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1076696.html
微信扫一扫
支付宝扫一扫