Skip to main content
The SHOW TABLES statement lists the schema, table name, table type, owner, and estimated row count for the tables or views in a schema or database.
While a table or view is being dropped, SHOW TABLES will list the object with a (dropped) suffix.

Synopsis

show_tables syntax diagram

Required privileges

The CONNECT privilege on the database of the concerned table is required to list it with SHOW TABLES.

Parameters

When a database_name and schema_name are omitted, the tables of the current schema in the current database are listed. SHOW TABLES will attempt to find a schema with the specified name first. If that fails, it will try to find a database with that name instead, and list the tables of its public schema. For more details, see Name Resolution.

Performance

To optimize the performance of the SHOW TABLES statement, you can do the following:
  • Disable table row-count estimation by setting the sql.show_tables.estimated_row_count.enabled cluster setting to false before executing a SHOW TABLES statement.
  • Avoid running SHOW TABLES on databases with a large number of tables (e.g., more than 10,000 tables).

Examples

Setup

The following examples use MovR, a fictional vehicle-sharing application, to demonstrate CockroachDB SQL statements. For more information about the MovR example application and dataset, see MovR: A Global Vehicle-sharing App. To follow along, run cockroach demo with the --nodes and --demo-locality flags. This command opens an interactive SQL shell to a temporary, multi-node in-memory cluster with the movr database preloaded and set as the current database.

Show tables in the current database

SHOW TABLES uses the current schema public set by default in search_path:
Alternatively, within the built-in SQL shell, you can use the \dt shell command:

Show tables in a different schema

You can show the tables in schemas other than the current schema. You can also show the schema by table:
Because movr is the current database, these statements return the same output:

Show tables in a different database

You can also show tables from a different database.
Because public is the current schema, these statements return the same output:

Show user-defined tables with comments

You can use COMMENT ON to add comments on a table.
To view a table’s comments:
You can also view comments on a table with SHOW CREATE:
For more information, see COMMENT ON.

Show virtual tables with comments

The virtual tables in the pg_catalog, information_schema, and crdb_internal schemas contain useful comments, often with links to further documentation. To view virtual tables with comments and documentation links, use SHOW TABLES FROM <virtual schema> WITH COMMENT:

Show locality of tables

For multi-region tables, you can display the locality of each table using the SHOW TABLES command.
  1. Set the primary region on movr to us-east:
    All tables will be REGIONAL BY TABLE in the primary region by default.
  2. Configure the users table to be REGIONAL BY ROW:
Locality information for tables is also available in the locality column within the crdb_internal.tables table.

See also