首页 > 数据库 > mysql教程 > 我们如何创建带有列列表的 MySQL 视图?

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

PHPz
发布: 2023-09-01 18:13:02
转载
1018 人浏览过

我们如何创建带有列列表的 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 视图?的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:tutorialspoint.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板