DESCRIBE 视图名;
或简写成:DESC 视图名;
mysql> CREATE TABLE studentinfo( -> ID INT(11) PRIMARY KEY, -> NAME VARCHAR(20), -> SCORE DECIMAL(4,2), -> SUBJECT VARCHAR(20), -> TEACHER VARCHAR(20)); Query OK, 0 rows affected (0.10 sec)
mysql> CREATE VIEW v_studentinfo AS SELECT name,score FROM studentinfo; Query OK, 0 rows affected (0.04 sec)
mysql> DESCRIBE v_studentinfo; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | name | varchar(20) | YES | | NULL | | | score | decimal(4,2) | YES | | NULL | | +-------+--------------+------+-----+---------+-------+ 2 rows in set (0.01 sec)注意:使用 DESC 的执行结果和使用 DESCRIBE 是一样的。
SHOW CREATE VIEW 视图名;
通过上面的语句,还可以查看创建视图的语句。创建视图的语句可以作为修改或者重新创建视图的参考,方便用户操作。mysql> SHOW CREATE VIEW v_studentinfo \G *************************** 1. row *************************** View: v_studentinfo Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_studentinfo` AS select `studentinfo`.`NAME` AS `name`,`studentinfo`.`SCORE` AS `score` from `studentinfo` character_set_client: gbk collation_connection: gbk_chinese_ci 1 row in set (0.00 sec)上述 SQL 语句以
\G
结尾,这样能使显示结果格式化。如果不使用\G
,显示的结果会比较混乱,如下所示:
mysql> DESCRIBE v_studentinfo; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | name | varchar(20) | YES | | NULL | | | score | decimal(4,2) | YES | | NULL | | +-------+--------------+------+-----+---------+-------+ 2 rows in set (0.01 sec) mysql> SHOW CREATE VIEW v_studentinfo; +---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+ | View | Create View | character_set_client | collation_connection | +---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+ | v_studentinfo | CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_studentinfo` AS select `studentinfo`.`NAME` AS `name`,`studentinfo`.`SCORE` AS `score` from `studentinfo` | gbk | gbk_chinese_ci | +---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+ 1 row in set (0.01 sec)
SELECT * FROM information_schema.views;
不过,通常情况下都是使用 SHOW CREATE VIEW 语句。
本文链接:http://task.lmcjl.com/news/15887.html