How can we create MySQL views without any column list?



While creating a view, providing the list of columns is optional. The following example will illustrate by creating the views without any 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 AS SELECT * FROM Student_Detail;
Query OK, 0 rows affected (0.17 sec)

As we can notice in the query below that while creating the view we have not given any column names and that is why it is the view without column list. Now, if we will run the query using the name of the view then we will get all the columns from the table on which it is created.

mysql> Select * from View_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.00 sec)
Samual Sam
Samual Sam

Learning faster. Every day.


Advertisements