SHOW TABLES

On this page Carat arrow pointing down
Warning:
CockroachDB v19.1 is no longer supported. For more details, see the Release Support Policy.

The SHOW TABLES statement lists the tables or views in a schema or database.

Note:
While a table or view is being dropped, SHOW TABLES will list the object with a (dropped) suffix.

Synopsis

SHOW TABLES FROM database_name . schema_name WITH COMMENT

Required privileges

No privileges are required to list the tables in a schema or database.

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.

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.

Examples

These example assumes that the bank database has been set as the current database for the session, either via the SET statement or in the client's connection string.

Show tables in the current database

icon/buttons/copy
> SHOW TABLES;
+---------------+
| table_name    |
+---------------+
| accounts      |
| user_accounts |
+---------------+
(2 rows)

This uses the current schema public set by default in search_path.

Show tables in a different schema

icon/buttons/copy
> SHOW TABLES FROM information_schema;
icon/buttons/copy
> SHOW TABLES FROM bank.information_schema; -- also possible
+-----------------------------------+
|            table_name             |
+-----------------------------------+
| administrable_role_authorizations |
| applicable_roles                  |
| column_privileges                 |
| columns                           |
| constraint_column_usage           |
| enabled_roles                     |
| key_column_usage                  |
| parameters                        |
| referential_constraints           |
| role_table_grants                 |
| routines                          |
| schema_privileges                 |
| schemata                          |
| sequences                         |
| statistics                        |
| table_constraints                 |
| table_privileges                  |
| tables                            |
| user_privileges                   |
| views                             |
+-----------------------------------+
(20 rows)

Show tables in a different database

icon/buttons/copy
> SHOW TABLES FROM startrek.public;
icon/buttons/copy
> SHOW TABLES FROM startrek; -- also possible
+-------------------+
| table_name        |
+-------------------+
| episodes          |
| quotes            |
| quotes_per_season |
+-------------------+
(3 rows)

Show tables with comments

New in v19.1:You can use COMMENT ON to add comments on a table. To view a table's comments:

> SHOW TABLES FROM customers WITH COMMENT;
  table_name |         comment
+------------+--------------------------+
  dogs       | This is a sample comment
(1 row)

For more information, see COMMENT ON.

See also


Yes No
On this page

Yes No