在 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)
广告