Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> MySQL

Tạo View MySQL không có danh sách cột

Khi tạo view, danh sách cột là tùy chọn. Ví dụ tạo view không chỉ định cột:

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)

View không có column list nên khi truy vấn sẽ trả về tất cả cột của bảng gốc:

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)