登录
首页 >  数据库 >  MySQL

我们如何创建带有列列表的 MySQL 视图?

来源:tutorialspoint

时间:2023-08-26 12:18:53 247浏览 收藏

最近发现不少小伙伴都对数据库很感兴趣,所以今天继续给大家介绍数据库相关的知识,本文《我们如何创建带有列列表的 MySQL 视图?》主要内容涉及到等等知识点,希望能帮到你!当然如果阅读本文时存在不同想法,可以在评论中表达,但是请勿使用过激的措辞~

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)

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《我们如何创建带有列列表的 MySQL 视图?》文章吧,也可关注golang学习网公众号了解相关技术文章。

声明:本文转载于:tutorialspoint 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>