首頁 > 資料庫 > 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 −example will illustrate by creating the views with column list −s colum#

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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板