SHOW TABLES

功能描述

查看当前库(或schema)的表清单。

注意事项

  • 若不指定db_name,查询的是当前库(或schema)下的表清单。

语法格式

  1. SHOW [FULL] TABLES
  2. [{FROM | IN} db_name]
  3. [LIKE 'pattern' | WHERE expr]

参数说明

  • db_name

    库名(或schema),可选项,若不指定,则查询的是当前库或schema。

  • LIKE ‘pattern’

    pattern匹配显示结果第一列(列名为’Tables_in_dbname [pattern]‘)。

示例

  1. --创建简单表
  2. openGauss=# CREATE SCHEMA tst_schema;
  3. openGauss=# SET SEARCH_PATH TO tst_schema;
  4. openGauss=# CREATE TABLE tst_t1
  5. openGauss-# (
  6. openGauss(# id int primary key,
  7. openGauss(# name varchar(20) NOT NULL,
  8. openGauss(# addr text COLLATE "de_DE",
  9. openGauss(# phone text COLLATE "es_ES",
  10. openGauss(# addr_code text
  11. openGauss(# );
  12. openGauss=# CREATE VIEW tst_v1 AS SELECT * FROM tst_t1;
  13. openGauss=# CREATE TABLE t_t2(id int);
  14. --查看库(或SCHEMA)下表清单信息
  15. openGauss=# show tables;
  16. Tables_in_tst_schema
  17. ----------------------
  18. tst_t1
  19. tst_v1
  20. t_t2
  21. openGauss=# show full tables;
  22. Tables_in_tst_schema | Table_type
  23. ----------------------+------------
  24. tst_t1 | BASE TABLE
  25. tst_v1 | VIEW
  26. t_t2 | BASE TABLE
  27. openGauss=# show full tables in tst_schema;
  28. Tables_in_tst_schema | Table_type
  29. ----------------------+------------
  30. tst_t1 | BASE TABLE
  31. tst_v1 | VIEW
  32. t_t2 | BASE TABLE
  33. --模糊匹配、过滤
  34. openGauss=# show full tables like '%tst%';
  35. Tables_in_tst_schema (%tst%) | Table_type
  36. ------------------------------+------------
  37. tst_t1 | BASE TABLE
  38. tst_v1 | VIEW
  39. openGauss=# show full tables where Table_type='VIEW';
  40. Tables_in_tst_schema | Table_type
  41. ----------------------+------------
  42. tst_v1 | VIEW