SHOW TABLES

Description

The SHOW TABLES statement returns all the tables for an optionally specified database. Additionally, the output of this statement may be filtered by an optional matching pattern. If no database is specified then the tables are returned from the current database.

Syntax

  1. SHOW TABLES [ { FROM | IN } database_name ] [ LIKE regex_pattern ]

Parameters

  • { FROM | IN } database_name

    Specifies the database name from which tables are listed.

  • regex_pattern

    Specifies the regular expression pattern that is used to filter out unwanted tables.

    • Except for * and | character, the pattern works like a regular expression.
    • * alone matches 0 or more characters and | is used to separate multiple different regular expressions, any of which can match.
    • The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive.

Examples

  1. -- List all tables in default database
  2. SHOW TABLES;
  3. +--------+---------+-----------+
  4. |database|tableName|isTemporary|
  5. +--------+---------+-----------+
  6. | default| sam| false|
  7. | default| sam1| false|
  8. | default| suj| false|
  9. +--------+---------+-----------+
  10. -- List all tables from userdb database
  11. SHOW TABLES FROM userdb;
  12. +--------+---------+-----------+
  13. |database|tableName|isTemporary|
  14. +--------+---------+-----------+
  15. | userdb| user1| false|
  16. | userdb| user2| false|
  17. +--------+---------+-----------+
  18. -- List all tables in userdb database
  19. SHOW TABLES IN userdb;
  20. +--------+---------+-----------+
  21. |database|tableName|isTemporary|
  22. +--------+---------+-----------+
  23. | userdb| user1| false|
  24. | userdb| user2| false|
  25. +--------+---------+-----------+
  26. -- List all tables from default database matching the pattern `sam*`
  27. SHOW TABLES FROM default LIKE 'sam*';
  28. +--------+---------+-----------+
  29. |database|tableName|isTemporary|
  30. +--------+---------+-----------+
  31. | default| sam| false|
  32. | default| sam1| false|
  33. +--------+---------+-----------+
  34. -- List all tables matching the pattern `sam*|suj`
  35. SHOW TABLES LIKE 'sam*|suj';
  36. +--------+---------+-----------+
  37. |database|tableName|isTemporary|
  38. +--------+---------+-----------+
  39. | default| sam| false|
  40. | default| sam1| false|
  41. | default| suj| false|
  42. +--------+---------+-----------+