Documentation Home
MySQL 9.4 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 41.2Mb
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.4 Reference Manual  / ...  / INFORMATION_SCHEMA Tables  / INFORMATION_SCHEMA General Tables  /  The INFORMATION_SCHEMA VIEWS Table

28.3.53 The INFORMATION_SCHEMA VIEWS Table

TheVIEWS table provides information about views in databases. You must have theSHOW VIEW privilege to access this table.

TheVIEWS table has these columns:

  • TABLE_CATALOG

    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_NAME

    The name of the view.

  • VIEW_DEFINITION

    TheSELECT statement that provides the definition of the view. This column has most of what you see in theCreate Table column thatSHOW CREATE VIEW produces. Skip the words beforeSELECT and 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_OPTION

    The value of theCHECK_OPTION attribute. The value is one ofNONE,CASCADE, orLOCAL.

  • IS_UPDATABLE

    MySQL sets a flag, called the view updatability flag, atCREATE VIEW time. The flag is set toYES (true) ifUPDATE andDELETE (and similar operations) are legal for the view. Otherwise, the flag is set toNO (false). TheIS_UPDATABLE column in theVIEWS table displays the status of this flag. It means that the server always knows whether a view is updatable.

    If a view is not updatable, statements suchUPDATE,DELETE, andINSERT are illegal and are rejected. (Even if a view is updatable, it might not be possible to insert into it; for details, refer toSection 27.6.3, “Updatable and Insertable Views”.)

  • DEFINER

    The account of the user who created the view, in'user_name'@'host_name' format.

  • SECURITY_TYPE

    The viewSQL SECURITY characteristic. The value is one ofDEFINER orINVOKER.

  • CHARACTER_SET_CLIENT

    The session value of thecharacter_set_client system variable when the view was created.

  • COLLATION_CONNECTION

    The session value of thecollation_connection system variable when the view was created.

Notes

MySQL permits differentsql_mode settings to tell the server the type of SQL syntax to support. For example, you might use theANSI 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 thesql_mode setting to a value different fromANSI 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 aCONCAT() 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.VIEWS       WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'v';+----------------------------------+| VIEW_DEFINITION                  |+----------------------------------+| 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 ofsql_mode do not affect the results from the view. However, an additional consequence is that comments prior toSELECT are stripped from the definition by the server.