在 MySQL 中顯示 VIEW 的內容?


以下是語法 -

select * from yourViewName;

讓我們首先建立一個表 -

mysql> create table DemoTable1388
   -> (
   -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> StudentName varchar(40)
   -> );
Query OK, 0 rows affected (0.71 sec)

使用 insert 命令向表中插入一些記錄 -

mysql> insert into DemoTable1388(StudentName) values('Chris');
Query OK, 1 row affected (0.23 sec)
mysql> insert into DemoTable1388(StudentName) values('Bob');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable1388(StudentName) values('David');
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable1388(StudentName) values('Mike');
Query OK, 1 row affected (0.29 sec)

使用 select 語句從表中顯示所有記錄 -

mysql> select * from DemoTable1388;

這將產生以下輸出 -

+-----------+-------------+
| StudentId | StudentName |
+-----------+-------------+
|         1 | Chris       |
|         2 | Bob         |
|         3 | David       |
|         4 | Mike        |
+-----------+-------------+
4 rows in set (0.00 sec)

以下是 MySQL 中建立檢視的查詢 -

mysql> create view view1388 as select *from DemoTable1388 where StudentId=3;
Query OK, 0 rows affected (0.13 sec)

現在,在 MySQL 中顯示檢視的內容 -

mysql> select * from view1388;

這將產生以下輸出 -

+-----------+-------------+
| StudentId | StudentName |
+-----------+-------------+
|         3 | David       |
+-----------+-------------+
1 row in set (0.19 sec)

更新於: 11-11-2019

1 千 + 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.