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 視圖?的詳細內容,更多請關注www.92cms.cn其它相關文章!