SHOW TABLES lists the schema, table name, table type, owner, and estimated row count for the tables or in a schema or database.
While a table or view is being ,
SHOW TABLES will list the object with a (dropped) suffix.Synopsis
Required privileges
TheCONNECT on the database of the concerned table is required to list it with SHOW TABLES.
Parameters
| Parameter | Description |
|---|---|
database\_name | The name of the database for which to show tables. |
schema\_name | The name of the schema for which to show tables. |
database_name and schema_name are omitted, the tables of the in the 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 .
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.enabledtofalsebefore 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 . To follow along, run with the and flags. This command opens an interactive SQL shell to a temporary, multi-node in-memory cluster with themovr database preloaded and set as the .
Show tables in the current database
SHOW TABLES uses the public set by default in search_path:
\dt :
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 use to add comments on a table.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 tables, you can display the locality of each table using theSHOW TABLES command.
-
on
movrtous-east:All tables will be in the primary region by default. -
Configure the
userstable to be :
Locality information for tables is also available in the
locality column within the table.
