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
Required privileges
TheCONNECT 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 theSHOW TABLES statement, you can do the following:
- Disable table row-count estimation by setting the
sql.show_tables.estimated_row_count.enabledcluster setting tofalsebefore executing aSHOW TABLESstatement. - Avoid running
SHOW TABLESon 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, runcockroach 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:
\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: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.public is the current schema, these statements return the same output:
Show user-defined tables with comments
You can useCOMMENT ON to add comments on a table.
SHOW CREATE:
COMMENT ON.
Show virtual tables with comments
The virtual tables in thepg_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 theSHOW TABLES command.
-
Set the primary region on
movrtous-east:All tables will beREGIONAL BY TABLEin the primary region by default. -
Configure the
userstable to beREGIONAL BY ROW:
Locality information for tables is also available in the
locality column within the crdb_internal.tables table.
