VIEWS 表提供数据库中视图的信息。您必须拥有 SHOW VIEW 权限才能访问此表。The VIEWS table provides information
about views in databases. You must have the
SHOW VIEW privilege to access this
table.
VIEWS 表包含以下列:The VIEWS table has these columns:
TABLE_CATALOG视图所属目录的名称。此值始终为
def。The name of the catalog to which the view belongs. This value is alwaysdef.TABLE_SCHEMA视图所属模式(数据库)的名称。The name of the schema (database) to which the view belongs.
TABLE_NAMETABLE_NAME视图的名称。The name of the view.
VIEW_DEFINITION提供视图定义的
SELECT语句。该列包含了SHOW CREATE VIEW生成的Create Table列中大部分内容。省略SELECT之前的词,并省略WITH CHECK OPTION。假设原始语句是:TheSELECTstatement that provides the definition of the view. This column has most of what you see in theCreate Tablecolumn thatSHOW CREATE VIEWproduces. Skip the words beforeSELECTand skip the wordsWITH CHECK OPTION. Suppose that the original statement was:CREATE VIEW v AS SELECT s2,s1 FROM t WHERE s1 > 5 ORDER BY s1 WITH CHECK OPTION;
然后视图定义如下:Then the view definition looks like this:
SELECT s2,s1 FROM t WHERE s1 > 5 ORDER BY s1
CHECK_OPTIONCHECK_OPTION属性的值。值可以是NONE、CASCADE或LOCAL之一。The value of theCHECK_OPTIONattribute. The value is one ofNONE,CASCADE, orLOCAL.IS_UPDATABLEMySQL 在
CREATE VIEW时设置一个名为视图可更新性标志的标志。如果视图允许执行UPDATE和DELETE(以及类似操作),则该标志设置为YES(真)。否则,该标志设置为NO(假)。VIEWS表中的IS_UPDATABLE列显示该标志的状态。这意味着服务器始终知道视图是否可更新。MySQL sets a flag, called the view updatability flag, atCREATE VIEWtime. The flag is set toYES(true) ifUPDATEandDELETE(and similar operations) are legal for the view. Otherwise, the flag is set toNO(false). TheIS_UPDATABLEcolumn in theVIEWStable displays the status of this flag. It means that the server always knows whether a view is updatable.如果一个视图不可更新,则像
UPDATE、DELETE和INSERT这样的语句是非法的,并会被拒绝。(即使视图可以更新,可能也无法向其插入数据;详情请参阅 第 27.5.3 节,“可更新和可插入视图”。)If a view is not updatable, statements suchUPDATE,DELETE, andINSERTare illegal and are rejected. (Even if a view is updatable, it might not be possible to insert into it; for details, refer to Section 27.5.3, “Updatable and Insertable Views”.)DEFINERDEFINER创建该视图的用户账户,格式为
'。The account of the user who created the view, inuser_name'@'host_name''format.user_name'@'host_name'SECURITY_TYPE视图的
SQL SECURITY特性。值可以是DEFINER或INVOKER。The viewSQL SECURITYcharacteristic. The value is one ofDEFINERorINVOKER.CHARACTER_SET_CLIENT创建视图时
character_set_client系统变量的会话值。The session value of thecharacter_set_clientsystem variable when the view was created.COLLATION_CONNECTION创建视图时
collation_connection系统变量的会话值。The session value of thecollation_connectionsystem variable when the view was created.
注意事项Notes
MySQL 允许不同的 sql_mode 设置,以告知服务器应支持的 SQL 语法类型。例如,你可以使用 ANSI SQL 模式,以确保 MySQL 在查询中正确解释标准 SQL 的连接运算符双竖线(||)。如果你随后创建了一个连接项目的视图,你可能会担心将 sql_mode 设置更改为与 ANSI 不同的值可能会导致视图无效。但事实并非如此。无论你如何编写视图定义,MySQL 总是以相同的标准形式存储它。下面是一个示例,显示服务器如何将双竖线连接运算符更改为 CONCAT() 函数:MySQL permits different sql_mode
settings to tell the server the type of SQL syntax to support. 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. 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. 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. Here is an example that shows how
the server changes a double bar concatenation operator to a
CONCAT() function:
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.00 sec) mysql>SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWSWHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'v';+----------------------------------+ | VIEW_DEFINITION | +----------------------------------+ | select concat('a','b') AS `col1` | +----------------------------------+ 1 row in set (0.00 sec)
以规范形式存储视图定义的优点是,后来对 sql_mode 值所做的更改不会影响视图的结果。然而,另一个副作用是,服务器会从定义中移除 SELECT 之前的注释。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. However, an additional consequence is that
comments prior to SELECT are
stripped from the definition by the server.