SHOW CREATE VIEW view_name
This statement shows the 此语句显示创建命名视图的CREATE VIEW statement that creates the named view.CREATE VIEW语句。
mysql> SHOW CREATE VIEW v\G
*************************** 1. row ***************************
View: v
Create View: CREATE ALGORITHM=UNDEFINED
DEFINER=`bob`@`localhost`
SQL SECURITY DEFINER VIEW
`v` AS select 1 AS `a`,2 AS `b`
character_set_client: utf8mb4
collation_connection: utf8mb4_0900_ai_ci
character_set_client is the session value of the 创建视图时character_set_client system variable when the view was created. character_set_client系统变量的会话值。collation_connection is the session value of the 是创建视图时collation_connection system variable when the view was created.collation_connection系统变量的会话值。
Use of 使用SHOW CREATE VIEW requires the SHOW VIEW privilege, and the SELECT privilege for the view in question.SHOW CREATE VIEW需要SHOW VIEW权限,以及相关视图的SELECT权限。
View information is also available from the 视图信息也可以从INFORMATION_SCHEMA VIEWS table. INFORMATION_SCHEMA视图表中获得。See Section 26.3.48, “The INFORMATION_SCHEMA VIEWS Table”.请参阅第26.3.48节,“INFORMATION_SCHEMA视图表”
MySQL lets you use different MySQL允许您使用不同的sql_mode settings to tell the server the type of SQL syntax to support. sql_mode设置来告诉服务器要支持的sql语法类型。For example, you might use the 例如,您可以使用ANSI SQL mode to ensure MySQL correctly interprets the standard SQL concatenation operator, the double bar (||), in your queries. ANSI SQL模式来确保MySQL正确解释查询中的标准SQL连接运算符,即双栏(||)。If you then create a view that concatenates items, you might worry that changing the 如果随后创建一个连接项的视图,可能会担心将sql_mode setting to a value different from ANSI could cause the view to become invalid. sql_mode设置更改为不同于ANSI的值可能会导致视图无效。But this is not the case. 但事实并非如此。No matter how you write out a view definition, MySQL always stores it the same way, in a canonical form. 无论您如何编写视图定义,MySQL总是以相同的方式以规范的形式存储它。Here is an example that shows how the server changes a double bar concatenation operator to a 下面的示例显示了服务器如何将双栏串联运算符更改为CONCAT() function:CONCAT()函数:
mysql>SET sql_mode = 'ANSI';Query OK, 0 rows affected (0.00 sec) mysql>CREATE VIEW test.v AS SELECT 'a' || 'b' as col1;Query OK, 0 rows affected (0.01 sec) mysql>SHOW CREATE VIEW test.v\G*************************** 1. row *************************** View: v Create View: CREATE VIEW "v" AS select concat('a','b') AS "col1" ... 1 row in set (0.00 sec)
The advantage of storing a view definition in canonical form is that changes made later to the value of 以规范形式存储视图定义的优点是,以后对sql_mode do not affect the results from the view. sql_mode的值所做的更改不会影响视图的结果。However an additional consequence is that comments prior to 然而,另一个后果是,服务器会从定义中删除SELECT are stripped from the definition by the server.SELECT之前的注释。