VIEWS

The VIEWS table provides information about SQL views.

  1. USE INFORMATION_SCHEMA;
  2. DESC VIEWS;

The output is as follows:

  1. +----------------------+--------------+------+------+---------+-------+
  2. | Field | Type | Null | Key | Default | Extra |
  3. +----------------------+--------------+------+------+---------+-------+
  4. | TABLE_CATALOG | varchar(512) | NO | | NULL | |
  5. | TABLE_SCHEMA | varchar(64) | NO | | NULL | |
  6. | TABLE_NAME | varchar(64) | NO | | NULL | |
  7. | VIEW_DEFINITION | longtext | NO | | NULL | |
  8. | CHECK_OPTION | varchar(8) | NO | | NULL | |
  9. | IS_UPDATABLE | varchar(3) | NO | | NULL | |
  10. | DEFINER | varchar(77) | NO | | NULL | |
  11. | SECURITY_TYPE | varchar(7) | NO | | NULL | |
  12. | CHARACTER_SET_CLIENT | varchar(32) | NO | | NULL | |
  13. | COLLATION_CONNECTION | varchar(32) | NO | | NULL | |
  14. +----------------------+--------------+------+------+---------+-------+
  15. 10 rows in set (0.00 sec)

Create a view and query the VIEWS table:

  1. CREATE VIEW test.v1 AS SELECT 1;
  2. SELECT * FROM VIEWS\G

The output is as follows:

  1. *************************** 1. row ***************************
  2. TABLE_CATALOG: def
  3. TABLE_SCHEMA: test
  4. TABLE_NAME: v1
  5. VIEW_DEFINITION: SELECT 1
  6. CHECK_OPTION: CASCADED
  7. IS_UPDATABLE: NO
  8. DEFINER: root@127.0.0.1
  9. SECURITY_TYPE: DEFINER
  10. CHARACTER_SET_CLIENT: utf8mb4
  11. COLLATION_CONNECTION: utf8mb4_0900_ai_ci
  12. 1 row in set (0.00 sec)

Fields in the VIEWS table are described as follows:

  • TABLE_CATALOG: The name of the catalog to which the view belongs. This value is always def.
  • TABLE_SCHEMA: The name of the schema to which the view belongs.
  • TABLE_NAME: The view name.
  • VIEW_DEFINITION: The definition of view, which is made by the SELECT statement when the view is created.
  • CHECK_OPTION: The CHECK_OPTION value. The value options are NONE, CASCADE, and LOCAL.
  • IS_UPDATABLE: Whether UPDATE/INSERT/DELETE is applicable to the view. In TiDB, the value is always NO.
  • DEFINER: The name of the user who creates the view, which is in the format of 'user_name'@'host_name'.
  • SECURITY_TYPE: The value of SQL SECURITY. The value options are DEFINER and INVOKER.
  • CHARACTER_SET_CLIENT: The value of the character_set_client session variable when the view is created.
  • COLLATION_CONNECTION: The value of the collation_connection session variable when the view is created.

See also