如何在 MySQL 中创建一个空视图?

mysqlmysqli database更新于 2025/10/4 16:12:17

要在 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)

Let us check the description of the view −

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)

相关文章


有用资源