如何在 MySQL 中建立一個空的檢視?


要在 MySQL 中建立一個空檢視,可以使用以下語法 −

create or replace view yourViewName as
select yourValue AS yourColumnName,
yourValue AS yourColumnName2,
.
.
N
from dual
where false;

讓我們實現上述語法來在 MySQL 中建立一個空檢視 −

mysql> create or replace view empty_view as
   select "John Smith" AS ClientName,
   "US" AS ClientCountryName,
   false AS isMarried
   from dual
   where false;
Query OK, 0 rows affected (0.20 sec)

讓我們檢查檢視的描述 −

mysql> desc empty_view;

這將產生以下輸出 -

+-------------------+-------------+------+-----+---------+-------+
| Field             | Type        | Null | Key | Default | Extra |
+-------------------+-------------+------+-----+---------+-------+
| ClientName        | varchar(10) | NO   |     |         |       |
| ClientCountryName | varchar(2)  | NO   |     |         |       |
| isMarried         | int(1)      | NO   |     | 0       |       |
+-------------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

讓我們檢查一下檢視是否為空 −

mysql> select *from empty_view;
Empty set (0.00 sec)

更新於: 2019 年 8 月 22 日

665 次瀏覽

開啟你的 職業生涯吧

完成課程,獲得認證

開始吧
廣告